EntityFramework.Docs icon indicating copy to clipboard operation
EntityFramework.Docs copied to clipboard

Merging migrations by manual causes incorrect migration.Designer.cs metadata

Open kot-pilot opened this issue 2 years ago • 1 comments

Entity framework core seems to be really better suited for working on migrations in team environment than previous versions were. But merging migrations which were created in different branches (like mentioned in this manual https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/teams) will cause the last created migration's .Designer.cs metadata to be not correct (as it will contain snapshot, which won't include first merged migration's changes). As I understand, migration.Designer.cs snapshot is used when we call 'dotnet ef migrations remove' to restore previous version of ContextSnapshot, but in case with merged migrations restored snapshot will be wrong.

Here is the example repository which I've created to play around, which shows the situation. https://github.com/kot-pilot/frankenstein Initially I've created migration with table named 'First', then created 2 branches, one created migration with 'Second' table and another created migration with 'Third' table. After merging that branches migration.Designer.cs of Third's migration missing the information about 'Second' migration (https://github.com/kot-pilot/frankenstein/blob/master/frankenstein/EntityFramework/Migrations/20220414185644_third.Designer.cs) Now this causes that when I call 'dotnet ef migrations remove' ContextSnapshot is getting wrong state.

So the questions are:

  1. Maybe that situation should be mentioned in this manual? https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/teams
  2. Are there any further developing plans to prevent this situations to happen? Like for example don't store snapshots in migration.Designer.cs and when we call 'dotnet ef migrations remove' to try to calculate previous version of ContextSnapshot by somehow using migration's down method code and not by using migrations .Designer.cs metadata?

kot-pilot avatar Apr 18 '22 13:04 kot-pilot

This a major issue for my team. We have internal documentation that instructs us to ignore the Microsoft documentation since it is incomplete. Our documentation states that when doing a merge of latest changes into your feature branch you should remove your migration(s). merge, re-add your migration. This is a slow process though and has caused a lot of additional work when merging pull requests. I have to merge a pull request, then instruct the next pull request owner to pull in the changes and regenerate their migration. Rinse and repeat. After the team grows to a considerable size, this will no longer be an option as merges have to be coordinated with a lot of involvement of each developer.

jasekiw avatar Mar 16 '23 17:03 jasekiw