[size="6"]Yii 2 Migration v2[/size]
With this extension all your migrations can be generated automatically.
[size="5"]Typical use case scenario[/size]
This huge DB table on your local machine is finally polished and ready to be moved to production environment.
Now instead of writing the migration class down you can use this extension. Simply install it by adding
in the require section of your composer.json file and run composer update.
Alternatively for the same effect you can just run
composer require bizley/migration
Now add some basic configuration (preferably in the console config file):
'components' => [ // ... ], 'controllerMap' => [ 'migration' => [ 'class' => 'bizley\migration\controllers\MigrationController', ], ],
And you are ready to go (fortunately it needs to be done only once).
In the console run
php yii migration/create table_name --fixHistory=1
and you can find the migration file for this table_name table in your @app/migrations folder. In addition your local migration history table has been updated with this migration entry (fixHistory parameter).
Now you can copy this migration file to your production environment and run there php yii migrate/up to apply it.
Few days later you add one additional column to the same table. And again Yii 2 Migration v2 can help.
In the console run
php yii migration/update table_name --fixHistory=1
and you can find another migration file for the table_name table in your @app/migrations folder but now it only contains methods that modifies table instead of creating it. (Local migration history table has been again updated with this migration entry).
To make both environments even again copy new migration file and run there php yii migrate/up to apply it.
[size="5"]Migration extension can generate creating and updating migrations[/size]
Supports databases that are supported by Yii 2 core: CUBRID, MS SQL Server, MySQL, Oracle, PostgreSQL and SQLite.
Scans migration history to gather all previously applied changes and create virtual table schema that can be compared with the real one.
Generates general schema migrations or currently-used-DB-specific ones.
Can generate migrations for many tables at once.
Can update migration history table when generating the file.
Can show differences between current table structure and the one saved in migration files instead of generating migration.
What is not supported (unfortunately)
DB indexes (except unique indexes),
whole table comments (column comments are supported),
ON UPDATE and ON DELETE actions for foreign keys.
[size="6"]For all available parameters go to the GitHub repo: