You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commands: A way to see current Migrations status #577
I hope you don't mind if I suggest two additional commands for the following scenarios:
Check that all applied migrations exist in the assembly
Check that pending migrations will be applied chronologically after applied migrations
An applied migration may be missing from an assembly if a migration from one git branch is applied to the database, and then the user switches to another branch without rolling-back the migration from the other branch. This can happen for example when deploying feature branches to testing environments.
It would be nice to be able have CI tools test for this scenario and fail before performing a migration.
Likewise, a pending migration with a timestamp earlier than the timestamp of one or more applied migrations will occur when one git branch contains migrations that have been applied is then merged into another git branch containing pending migrations with earlier timestamps. This also seems to happen when deploying feature branches to testing environments.
Both of these scenarios can be frustrating to fix, so a command to prevent it from occurring in the first place would be very welcome.
Both of these scenarios can be checked programatically:
// Check that all applied migrations exist in the assemblyvarassemblyMigrations=context.Database.GetMigrations();varappliedMigrations=context.Database.GetAppliedMigrations();varpendingMigrations=context.Database.GetPendingMigrations();if(appliedMigrations.Any(a =>!assemblyMigrations.Contains(a)))thrownewException("There are applied migrations that do not exist in this assembly. All applied migrations must exist in the assembly. Aborting the migration.");
// Check that pending migrations will be applied chronologically after applied migrationsvarappliedTimestamps=appliedMigrations.Select(m =>Convert.ToUInt64(m.Substring(0,14)));varpendingTimestamps=pendingMigrations.Select(m =>Convert.ToUInt64(m.Substring(0,14)));if(appliedTimestamps.Any(a =>pendingTimestamps.Any(p =>a>p)))thrownewException("There are pending migrations with a timestamp less than the timestamps of one or more applied migrations. Migrations must be applied chronologically. Aborting the migration.");
Activity
[-]Migrations PowerShell: A way to see current status[/-][+]Commands: A way to see current Migraions status[/+][-]Commands: A way to see current Migraions status[/-][+]Commands: A way to see current Migrations status[/+]32 remaining items
br3nt commentedon Jul 23, 2019
These will be very useful commands!
I hope you don't mind if I suggest two additional commands for the following scenarios:
An applied migration may be missing from an assembly if a migration from one git branch is applied to the database, and then the user switches to another branch without rolling-back the migration from the other branch. This can happen for example when deploying feature branches to testing environments.
It would be nice to be able have CI tools test for this scenario and fail before performing a migration.
Likewise, a pending migration with a timestamp earlier than the timestamp of one or more applied migrations will occur when one git branch contains migrations that have been applied is then merged into another git branch containing pending migrations with earlier timestamps. This also seems to happen when deploying feature branches to testing environments.
Both of these scenarios can be frustrating to fix, so a command to prevent it from occurring in the first place would be very welcome.
Both of these scenarios can be checked programatically:
bricelam commentedon Aug 17, 2020
Splitting out the pending model changes feature into #22105
voroninp commentedon May 6, 2024
Hm... still no way to list applied migrations?