From f14578beb63500bf56841ae599620b76a62dc5c2 Mon Sep 17 00:00:00 2001 From: Alexandru Trandafir Catalin Date: Fri, 22 Nov 2019 11:25:40 +0200 Subject: [PATCH] Docs: Migration config for more than one DB engine (#288) [skip ci] Special configuration for an application that uses more than one DB engine to avoid mixing migrations from both systems. The problem it solves: - If you run both MySQL and MongoDB and have migrations for both, with the default configuration if you create a mongodb migration and try to run it, it will tell you that you have a lot of other pending migrations, that are actually MySQL migrations. --- docs/guide/topics-migrations.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/guide/topics-migrations.md b/docs/guide/topics-migrations.md index 60430d36d..4ae292079 100644 --- a/docs/guide/topics-migrations.md +++ b/docs/guide/topics-migrations.md @@ -30,3 +30,26 @@ yii mongodb-migrate # reverts the last applied migration yii mongodb-migrate/down ``` +## Special configuration for an application that uses more than one DB engine + +In case your application uses multiple databases, example: + +- MySQL + MongoDB + +If you run the migration commands, it will evaluate both MySQL and MongoDB migration files at the same time since both by default share the same folder. + +**Problem: MongoDB will try to run MySQL's migration files and the other way around.** + +In order to avoid that behavior, you can create a new folder called `mongodb` under your `migrations` folder, and then setup your console application like this: + +```php +return [ + // ... + 'controllerMap' => [ + 'mongodb-migrate' => [ + 'class' => 'yii\mongodb\console\controllers\MigrateController', + 'migrationPath' => '@app/migrations/mongodb', + ], + ], +]; +```