<?php namespace app\components; use yii\db\Migration; class CustomMigrationDb2 extends Migration{ public function init() { $this->db = 'db2'; parent::init(); } }
<?php /** * This view is used by console/controllers/MigrateController.php * The following variables are available in this view: */ /* @var $className string the new migration class name */ echo "<?php\n"; ?> use yii\db\Schema; use app\components\CustomMigrationDb2; class <?= $className ?> extends CustomMigrationDb2 { public function up() { } public function down() { echo "<?= $className ?> cannot be reverted.\n"; return false; } /* // Use safeUp/safeDown to run migration code within a transaction public function safeUp() { } public function safeDown() { } */ }
<?php namespace app\commands; use yii\console\controllers\MigrateController; class MigrateDb2Controller extends MigrateController { public $db = 'db2'; public $templateFile = '@app/views/migrations/migration_db2.php'; public $migrationPath = '@app/migrations/db2'; }
'controllerMap' => [ ... 'migrate' => [ 'class' => 'app\commands\MigrateDbController', ], ],
'controllerMap' => [ ... 'migrate' => [ // Fixture generation command line. 'class' => 'yii\console\controllers\MigrateController', 'db' => 'db', 'templateFile' => '@app/views/migrations/migration_db.php', 'migrationPath' => '@app/migrations/db' ], 'migrate-db' => [ // Fixture generation command line. 'class' => 'yii\console\controllers\MigrateController', 'db' => 'db', 'templateFile' => '@app/views/migrations/migration_db.php', 'migrationPath' => '@app/migrations/db' ], 'migrate-db2' => [ // Fixture generation command line. 'class' => 'yii\console\controllers\MigrateController', 'db' => 'db2', 'templateFile' => '@app/views/migrations/migration_db2.php', 'migrationPath' => '@app/migrations/db2' ], ],
yii migrate-db
yii migrate-db2
yii migrate-db/create
yii migrate-db2/create
Source: https://habr.com/ru/post/279701/
All Articles