M
M
matperez2016-02-01 19:24:56
Yii
matperez, 2016-02-01 19:24:56

How to perform all migrations from modules in Yii2 with one command?

Hello!
I have a middle-aged project in which a huge number of migrations have already accumulated. I would like to scatter them among the application modules in order to restore at least some order, but:

  • firstly, the application deploys automatically and I don’t want to modify the deployment rules for each new module with migrations
  • secondly, you can forget to apply migrations somewhere by hand, because you forgot that they are in this module.

So, did anyone bother with the fact that with one command to perform all possible migrations from all modules? Can some common directory be implemented so that modules can register their migrations, and ./yii migrate would run through this directory and apply everything? Maybe there is some ready-made solution for this?
// UPD: here is a solution for example https://github.com/deesoft/yii2-console
// UPD2: something similar is planned in 2.1 https://github.com/yiisoft/yii2/issues/9698

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
matperez, 2016-02-01
@matperez

All in all, https://github.com/deesoft/yii2-console turned out to be the easiest solution. I use it.

N
Nikita, 2016-02-01
@bitver

1 - you can make a script file with paths already written
2 - theoretically you can make a file parser that finds the desired directory and feeds the path to the standard tool

A
Anton Natarov, 2016-02-01
@HanDroid

Yii migrate already finds all the migrations that were not applied. And applies them in ascending order by timeStamp.
For individual modules, you can roll like this
interactive: Boolean - boolean (true by default). Specifies whether the migration should be performed interactively. If this value is true, then the user will be prompted before the command performs certain actions. You can set this value to false if the command is running in the background.

V
Viktor, 2017-04-14
@shviktor

In the config of the console application, write controllerMap for the migrate controller of the path to the migrations in the modules.
Here is an example:

'controllerMap' => [
        'migrate' => [
            'class' => 'yii\console\controllers\MigrateController',
            'migrationNamespaces' => [
                'app\modules\courses\migrations'
            ],
            // ...
        ],
    ],

And do not forget to register the appropriate namespace in the migration files

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question