DoctrineMigrationsBundle icon indicating copy to clipboard operation
DoctrineMigrationsBundle copied to clipboard

Flow of migration the migration_versions can be in a invalid state

Open mpoiriert opened this issue 3 years ago • 0 comments

We migrate from 2 to 3.

The sysadmin executed the migration not from the root directory of the project which triggered:

An Error Occurred! Error thrown while running command "doctrine:migrations:migrate --no-interaction --allow-no-migration --env=prod -vvv". Message: "Cannot load migrations from "src/Migrations" because it is not a valid directory"

He said that normally he wasn't executing it from the root directory.

Afterwards he execute it from the root directory and we got this:

[WARNING] You have 132 previously executed migrations in the database that are not registered migrations.

And the system tried to execute all the migrations.

I check the code and it seems that the upgrade version do a "diff" on the current schema and the new one. If a alter table is needed it execute it and try to migrate all the migration entry.

Problem in that case is that the alter table was done but the migration of the entries failed. Second time no alter table was needed.

Obviously it's not possible to do a transaction with alter table but here are my 2 suggestions:

  • Flag the completed migrations in the table itself with a custom id instead of checking the alter table only

  • Prepare all the queries before executing the alter table (loading the migrations directories) so there is less chance of the system failing and be left in a invalid state.

mpoiriert avatar Mar 04 '21 01:03 mpoiriert