doctrine/DoctrineMigrationsBundle

Migrations are not executed in the right order

hdasdoria opened this issue · 1 comments

Hi,

I don't know if I'm missing something, or if it's the wanted behavior, but migrations are not executed in the "right" order.

From what I understand, when I run doctrine:migrations:migrate, the migrations are executed in an alphabetical order. But the order is based on the full class name and uses the namespace of the migration.

So, in the case where there is multiple bundles depending on each others, the command will execute the migrations of the bundle A, then the bundle B, then the bundle C, no matter if a migration in bundle C or B is older than the ones in bundle A.

Example:

BundleA\Migrations\Version20210309XXXXXX (9th Mar)
BundleB\Migrations\Version20210203XXXXXX (3rd Feb)
BundleB\Migrations\Version20210312XXXXXX (12th Mar)
BundleC\Migrations\Version20210205XXXXXX (5th Feb)
BundleC\Migrations\Version20210311XXXXXX (11th Mar)

The list above is the order the migrations will be executed. It's in alphabetical order but not in version / date order.

So it's an issue if the migration BundleA\Migrations\Version20210309XXXXXX uses a column or a table created in BundleC\Migrations\Version20210205XXXXXX (which was created a month earlier).

The only solution I have is to run manually each migration...

As of 3.x , the migrations are sorted alphabetically regardless of the namespace, thus the current execution order is correct.

If you store migrations in multiple namespaces you need to provide your custom sorter, you can see in https://www.goetas.com/blog/multi-namespace-migrations-with-doctrinemigrations-30/ a guide on how to implement a custom migration sorter.