Generating migration from existing database in Yii or Laravel

后端 未结 9 917
南方客
南方客 2021-01-31 05:39

I\'m working on a project that has a fairly complex database (150+ tables). In order to be able to maintain changes, I\'ve decided to add migrations, preferably using Yii or Lar

9条回答
  •  情话喂你
    2021-01-31 06:22

    As for Yii 1.x, schmunk has created a wonderful database-command yiic command.

    This command covers only up migrations. You must write your own down migrations.

    To use it:

    1. Get the newest version from GitHub and put it's contents into /protected/commands folder (create one, if it does not exist). Note, that you need to put contents as is (without subfolder for this particular command), which is contrary to what we do for example for extensions.

    2. Rename EDatabaseCommand.php file (and class inside) to DatabaseCommand.php, if you want to use yiic database command (as suggested in docs). Without this fix, you'll have to use yiic edatabase command, as there's slight inconsistency between docs and the code (at least in the newest version, as of writing this; maybe schmunk is going to fix this).

    3. Having this, navigate back to protected folder in your console and execute yiic database dump migration_name --prefix=table_name.

    This will create a migration protected/runtime/migration_name.php file with proper date and time in the beginning of file name, filled with series of CDbMigration commands to recreate your database schema. Visit "Usage" section in the docs to read more about customizing command.

提交回复
热议问题