Ensure that the order of migrations is reliable #12966
Labels
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
punted-for-2.2
type-bug
Milestone
AFAIK the order on wich migrations are executed is important and it's derived from lexicographical order of migration id. Since each migration id has a fixed length prefix with the timestamp, then the migrations are supposed to execute in that order.
But digging into the code, i've the suspect that there is no real guaranty about this order: in fact it appears to me that the migrations order relies on the order of insertion in a Dictionary.
https://github.com/aspnet/EntityFrameworkCore/blob/4f65388bf68312e16fe07e62f79d8fad4e242f2a/src/EFCore.Relational/Migrations/Internal/MigrationsAssembly.cs#L49-L73
but FCL documentation states:
Isn't better to replace
var result = new Dictionary<string, TypeInfo>();
with
var result = new SortedList<string, TypeInfo>();
IMHO the same issue arises where
MigrationsAssembly.Migrations
is used:https://github.com/aspnet/EntityFrameworkCore/blob/4f65388bf68312e16fe07e62f79d8fad4e242f2a/src/EFCore.Relational/Migrations/Internal/Migrator.cs#L180-L234
here you can add an explicit
.OrderBy(m => m.Key)
also when calculatingmigrationsToApply
Thanks
The text was updated successfully, but these errors were encountered: