Search code examples
database-migrationcommand-line-interfaceyii

Permanently customize migration table in yiic migration


Is there anyway to permanently force yiic inside protected folder of my application, to always (no matter, what) use customized table name for migrations?

The only way, I found is "standard" way of yiic migrate --migrationTable=migrations. But this is very bad approach. Any (accidental or intentional) miss / forget in adding this extra parameter and entire migration will crack, as yiic will create new, empty tbl_migration table, instead of use proper migrations one.


Solution

  • class MyMigrateCommand extends MigrateCommand {
    
        public $migrationTable='migrations';
    
    }
    

    Also you can update yiic.php file:

    ...
    $app = Yii::createConsoleApplication($config);
    
    $statConfig = require_once(dirname(__FILE__).'/config/console.php');
    $app->configure($statConfig);
    
    $app->commandRunner->commands = $statConfig['commandMap'];
    ...
    

    and add into config:

    ...
    'commandMap' => array(
            'class'=>'system.cli.commands.MigrateCommand',
            'migrationTable'=>'stat_tbl_migration',
    ),
    ...