Yii2: Proposal: When running migrations with custom migrationPath, copy them to app migrationPath

Created on 27 Feb 2017  路  5Comments  路  Source: yiisoft/yii2

If we run migrate with a custom --migrationPath the migration will be executed and added to our local migration table, but the migration file itself will remain in the custom path, with no record of where it came from. This makes it impossible to redo the whole migration history (for example by running something like migrate/redo 999). It will simply fail due to missing files.

Why not copy the files to the application's "master" migrationPath?

Not only does this ensure the global migration chain is not broken, but it also allows us to customize migrations we include from 3rd party sources.

Alternatively, the migrations could even be "re-created" with new (current) timestamps within the main application's migration directory to prevent potential naming conflicts and ensure they can always be executed in the same order as they were added.

under discussion enhancement

Most helpful comment

Applying migrations from sevral paths has been resolved by namespaced migrations at #12511.
We do not plan any further improvement of migrationPath functionality.

Why not copy the files to the application's "master" migrationPath?

Copying files is the worst solution as it causes the duplication of code, which will cause synchronization break and possible VSC collisions.

The best way for yu to solve your use case is using direct migration class inheritance, creating local migraiton class in your 'master' migration path, which extends migration from other source;

require Yii::getAlias('@some/extension/migrations/m..._create_foo_from_extension.php');

class m...._create_foo extends m..._create_foo_from_extension
{
    // blank
}

Still there is an opne issue with similar request at #13359.

All 5 comments

That actually makes sense. @klimov-paul what do you think?

Applying migrations from sevral paths has been resolved by namespaced migrations at #12511.
We do not plan any further improvement of migrationPath functionality.

Why not copy the files to the application's "master" migrationPath?

Copying files is the worst solution as it causes the duplication of code, which will cause synchronization break and possible VSC collisions.

The best way for yu to solve your use case is using direct migration class inheritance, creating local migraiton class in your 'master' migration path, which extends migration from other source;

require Yii::getAlias('@some/extension/migrations/m..._create_foo_from_extension.php');

class m...._create_foo extends m..._create_foo_from_extension
{
    // blank
}

Still there is an opne issue with similar request at #13359.

@klimov-paul That's a good point.

And thank you for the solution. It is exactly what I needed. It would be really great if it could be added to the documentation as well.

It is better to be mentioned at cook-book as it is complex use case.

That works too.

Was this page helpful?
0 / 5 - 0 ratings