Skip to content
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

Conversation

bergmania
Copy link
Member

@bergmania bergmania commented Apr 19, 2024

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 the UnscopedMigrationBase 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 migration

Breaking changes

  • Migrations that inherit UnscopedMigrationBase now have to call Context.Complete() when done.

Test

  • Ensure migrations from v13 is possible
    • Sqlite
    • SqlServer

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
Comment on lines 13 to 21
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;
Copy link
Contributor

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.

Copy link
Contributor

@nikolajlauridsen nikolajlauridsen left a 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.

@nikolajlauridsen nikolajlauridsen merged commit 7b46d44 into v14/dev Apr 22, 2024
14 of 16 checks passed
@nikolajlauridsen nikolajlauridsen deleted the v14/bugfix/migrations-do-not-persist-state-after-each-migration branch April 22, 2024 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants