PHPackages                             flameartlab/migration - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. flameartlab/migration

ActiveYii2-extension[Database &amp; ORM](/categories/database)

flameartlab/migration
=====================

Migration generator for Yii 2.

v2.2.9(8y ago)0254Apache-2.0PHP

Since Jul 11Pushed 8y agoCompare

[ Source](https://github.com/FlameArtLab/yii2-migration)[ Packagist](https://packagist.org/packages/flameartlab/migration)[ RSS](/packages/flameartlab-migration/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (1)Versions (21)Used By (0)

Yii2 advanced migration
=======================

[](#yii2-advanced-migration)

[![Latest Stable Version](https://camo.githubusercontent.com/0a49ad7dfc8dd686d0c1863b4bbf1d405853dc6c92358f53e7bedd68912ea6a2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f666c616d656172746c61622f6d6967726174696f6e2e737667)](https://camo.githubusercontent.com/0a49ad7dfc8dd686d0c1863b4bbf1d405853dc6c92358f53e7bedd68912ea6a2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f666c616d656172746c61622f6d6967726174696f6e2e737667)[![Total Downloads](https://camo.githubusercontent.com/ecf2901331171f6ca71c84316baf9c9a85e995e1902530a67982a9ac57d4937d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f666c616d656172746c61622f6d6967726174696f6e2e737667)](https://packagist.org/packages/flameartlab/migration)[![License](https://camo.githubusercontent.com/8f55cec090d103f0f7f894fec21014846bc40abb90096671b95b36e0738d46a2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f62697a6c65792f6d6967726174696f6e2e737667)](https://camo.githubusercontent.com/8f55cec090d103f0f7f894fec21014846bc40abb90096671b95b36e0738d46a2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f62697a6c65792f6d6967726174696f6e2e737667)

Migration creator and updater
-----------------------------

[](#migration-creator-and-updater)

Generates migration file based on the existing database table and previous migrations.

**NEW in that fork:**

- New command `fill table_name`. You can create migration for copy all table rows. The feature works with empty and NULL values correctly
- Added migrations for Key indexes (and unique indexes is working fine too)
- Added *comments* for tables in `create ` module
- Bug fixes

Installation
------------

[](#installation)

Add the package to your composer.json:

```
{
    "require": {
        "flameartlab/migration": "*"
    }
}

```

and run `composer update` or alternatively run `composer require flameartlab/migration`

Basic configuration
-------------------

[](#basic-configuration)

Add the following in your configuration file (preferably console configuration file):

```
'components' => [
    // ...
],
'controllerMap' => [
    'migration' => [
        'class' => 'bizley\migration\controllers\MigrationController',
    ],
],

```

Usage
-----

[](#usage)

The following console command are available:

```
php yii migration

```

or

```
php yii migration/list

```

Lists all the tables in the database.

```
php yii migration/create table_name

```

Generates migration to create DB table `table_name`.

```
php yii migration/create-all

```

Generates migrations to create all DB tables.

```
php yii migration/update table_name

```

Generates migration to update DB table `table_name`.

```
php yii migration/update-all

```

Generates migrations to update all DB tables.

```
php yii migration/fill table_name

```

Generates migration to fill DB table `table_name`.

You can generate multiple migrations for many tables at once by separating the names with a comma:

```
php yii migration/create table_name1,table_name2,table_name3

```

Updating migration
------------------

[](#updating-migration)

Starting with yii2-migration v2.0 it is possible to generate updating migration for database table.

1. History of applied migrations is scanned to gather all modifications made to the table.
2. Virtual table schema is prepared and compared with current table schema.
3. Differences are generated as update migration.
4. In case of migration history not keeping information about the table creating migration is generated.

Command line parameters
-----------------------

[](#command-line-parameters)

commandaliasdescription`db`Application component's ID of the DB connection to use when generating migrations. *default:* `'db'``migrationPath``p`Directory storing the migration classes. *default:* `'@app/migrations'``migrationNamespace``n`Namespace in case of generating namespaced migration. *default:* `null``templateFile``F`Template file for generating create migrations. *default:* `'@vendor/bizley/migration/src/views/create_migration.php'``templateFileUpdate``U`Template file for generating update migrations. *default:* `'@vendor/bizley/migration/src/views/update_migration.php'``useTablePrefix``P`Whether the table names generated should consider the `tablePrefix` setting of the DB connection. *default:* `1``migrationTable``t`Name of the table for keeping applied migration information. *default:* `'{{%migration}}'``showOnly``s`Whether to only display changes instead of generating update migration. *default:* `0``generalSchema``g`Whether to use general column schema instead of database specific (1). *default:* `0``fixHistory``h`Whether to add migration history entry when migration is generated. *default:* `0``skipMigrations`List of migrations from the history table that should be skipped during the update process (2). *default:* `[]`(1) Remember that with different database types general column schemas may be generated with different length.

> ### MySQL examples:
>
> [](#mysql-examples)
>
> Column `varchar(45)`
> generalSchema=0: `$this->string(45)`
> generalSchema=1: `$this->string()`
> Column `int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY`
> generalSchema=0: `$this->integer(11)->notNull()->append('AUTO_INCREMENT PRIMARY KEY')`
> generalSchema=1: `$this->primaryKey()`

(2) Here you can place migrations containing actions that can not be covered by extractor i.e. when there is a migration setting the RBAC hierarchy with authManager component. Such actions should be kept in separated migration and placed on this list to prevent them from being run during the extraction process.

Renaming
--------

[](#renaming)

When you rename table or column remember to generate appropriate migration manually otherwise this extension will not generate updating migration (in case of the table) or will generate migration with command to drop original column and add renamed one (in case of the column). This is happening because yii2-migration can only compare two states of the table without the knowledge of how one state turned into another. And while the very result of migration renaming the column and the one dropping it and adding another is the same in terms of structure, the latter **makes you lose data**.

Once you add renaming migration to the history it's being tracked by the extension.

Notes
-----

[](#notes)

This extension is tested on MySQL database but should work with all database types supported in Yii 2 core:

- CUBRID (9.3.x and higher)
- MS SQL Server (2008 and above)
- MySQL (4.1.x and 5.x)
- Oracle
- PostgreSQL (9.x and above)
- SQLite (2/3)

Let me know if something is wrong with databases other than MySQL (and in case of MySQL let me know as well).

As far as I know Yii 2 does not keep information about table indexes (except unique ones) and foreign keys' ON UPDATE and ON DELETE actions so unfortunately this can not be tracked and applied to generated migrations - you have to add it on your own.

Only history of migrations extending `yii\db\Migration` class can be properly scanned and only changes applied with default `yii\db\Migration` methods can be recognised (with the exception of `execute()`, `addCommentOnTable()` and `dropCommentFromTable()` methods). Changes made to table's data (like `insert()`, `delete()`, `truncate()`, etc.) are not tracked.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 60% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~30 days

Recently: every ~0 days

Total

20

Last Release

3029d ago

Major Versions

1.1 → 2.02017-03-26

### Community

Maintainers

![](https://www.gravatar.com/avatar/97ff964658f27ab904cf688ab184af96e7a022c87e60fc717ee1c3094eece38e?d=identicon)[FlameArtLab](/maintainers/FlameArtLab)

---

Top Contributors

[![thyseus](https://avatars.githubusercontent.com/u/654271?v=4)](https://github.com/thyseus "thyseus (6 commits)")[![FlameArt](https://avatars.githubusercontent.com/u/10730086?v=4)](https://github.com/FlameArt "FlameArt (4 commits)")

---

Tags

consolemigrationgeneratoryii2migrate

### Embed Badge

![Health badge](/badges/flameartlab-migration/health.svg)

```
[![Health](https://phpackages.com/badges/flameartlab-migration/health.svg)](https://phpackages.com/packages/flameartlab-migration)
```

###  Alternatives

[bizley/migration

Migration generator for Yii 2.

297374.3k11](/packages/bizley-migration)[dmstr/yii2-migrate-command

Console Migration Command with multiple paths/aliases support

31295.5k6](/packages/dmstr-yii2-migrate-command)[yii2tech/illuminate

Yii2 to Laravel Migration Package

11315.1k](/packages/yii2tech-illuminate)[e282486518/yii2-console-migration

yii2命令行中使用migration备份和还原数据库

388.1k4](/packages/e282486518-yii2-console-migration)[hzhihua/yii2-dump

Generate the schema from an existing database

1828.5k1](/packages/hzhihua-yii2-dump)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
