Skip to content

Migration replay - #1013

Closed
SimonCropp wants to merge 2 commits into
mainfrom
migration-replay
Closed

Migration replay#1013
SimonCropp wants to merge 2 commits into
mainfrom
migration-replay

Conversation

@SimonCropp

Copy link
Copy Markdown
Owner

No description provided.

Migrations are normally only ever tested against a database built by migrating
an empty one. Deployed databases are not like that: a deployment applies state
after migrating, such as change tracking, views, or grants, and that state can
make DDL that is valid against an empty database fail against a real one. SQL
Server refuses to drop a primary key while change tracking is on, so a
migration doing that passes every test and then fails on deploy.

ReplayRecentMigrations applies the last N migrations one at a time, running a
callback after each, so each migration meets the conditions a deployment gives
it. Everything before the window is applied in one hop.

The one at a time part is load bearing. Applying the window in a single hop and
running the callback once at the end is not equivalent, because a table created
inside the window never has the state applied before a later migration alters
it. ChangeTrackingReplayTests covers exactly that shape, and fails if the
implementation is changed to the single hop version.

Throws for a database that already has migrations applied, rather than letting
EF revert them by running their Down.
@SimonCropp SimonCropp added this to the 25.1.0 milestone Aug 4, 2026
@SimonCropp SimonCropp closed this Aug 5, 2026
@SimonCropp
SimonCropp deleted the migration-replay branch August 5, 2026 00:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant