-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RC2 Breaking - Ensure migrations persist the executed key, when executed. #16113
RC2 Breaking - Ensure migrations persist the executed key, when executed. #16113
Conversation
This requires a migration to call Context.SetDone() on the migration context. This happens automatically on scoped migrations before the scope is completed. But migrations inheriting the UnScopedMigrationBase needs to call this manually, inside the scopes or when it is considered done. Thereby, we minimize the risk (and eliminate it for SqlServer) that a migration is executed but the state is not saved. If a migration is executed without the SetDone is called, the migration upgrader throws an error, so we do not start executing the next migration
private readonly Action _onDoneAction; | ||
private readonly List<Type> _postMigrations = new(); | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="MigrationContext" /> class. | ||
/// </summary> | ||
public MigrationContext(MigrationPlan plan, IUmbracoDatabase? database, ILogger<MigrationContext> logger) | ||
public MigrationContext(MigrationPlan plan, IUmbracoDatabase? database, ILogger<MigrationContext> logger, Action onDoneAction) | ||
{ | ||
_onDoneAction = onDoneAction; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should also be renamed (completeAction?). Same with OnMigrationDone
method in class below and the comment referring to OnDone
.
Maybe this last parameter can be optional? Then you don't have to pass in nop action everywhere in tests.
…ugfix/migrations-do-not-persist-state-after-each-migration
…sist-state-after-each-migration' into v14/bugfix/migrations-do-not-persist-state-after-each-migration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good and tests good 🎉 👍.
I did however remove the public
access modifiers from the interface, and added a missing space to the error message.
Description
Adds new functionality to the migrations, to avoid the situration where a migration is executed, but Umbraco stops, before the KeyValue with migration state is updated.
This requires a migration to call
Context.Complete()
on the migration context. This happens automatically on scoped migrations before the scope is completed. But migrations inheriting theUnscopedMigrationBase
needs to call this manually, inside the scopes or at least when it is considered done.Thereby, we minimize the risk (and eliminate it for SqlServer) that a migration is executed but the state is not saved.
If a migration is executed without the
Complete
is called, the migration upgrader throws an error, so we do not start executing the next migrationBreaking changes
UnscopedMigrationBase
now have to callContext.Complete()
when done.Test