-
Notifications
You must be signed in to change notification settings - Fork 547
Fix database version stamp running before its own migrations #756
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
src/Core/Grand.Infrastructure/Migrations/IMigrationVersionStamp.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| namespace Grand.Infrastructure.Migrations; | ||
|
|
||
| /// <summary> | ||
| /// Marks the migration that records a database version as reached. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// A version stamp must be the last migration to run for its <see cref="IBaseMigration.Version" />, and it must only | ||
| /// run when every other migration of that version succeeded. <see cref="MigrationManager.GetCurrentMigrations" /> | ||
| /// filters by version, so a version recorded before its own migrations completed makes them unreachable forever — | ||
| /// they compare equal to the installed version and are never selected again. | ||
| /// </remarks> | ||
| public interface IMigrationVersionStamp : IMigration; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 4 additions & 29 deletions
33
src/Modules/Grand.Module.Migration/Migrations/1.1/MigrationUpgradeDbVersion_11.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,10 @@ | ||
| using Grand.Data; | ||
| using Grand.Domain.Common; | ||
| using Grand.Infrastructure; | ||
| using Grand.Infrastructure.Migrations; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| namespace Grand.Module.Migration.Migrations._1._1; | ||
|
|
||
| public class MigrationUpgradeDbVersion_11 : IMigration | ||
| public class MigrationUpgradeDbVersion_11 : MigrationUpgradeDbVersionBase | ||
| { | ||
| public int Priority => 0; | ||
| public override DbVersion Version => new(1, 1); | ||
|
|
||
| public DbVersion Version => new(1, 1); | ||
|
|
||
| public Guid Identity => new("6BDB7093-4C31-4D78-9604-58188DF728D3"); | ||
|
|
||
| public string Name => "Upgrade version of the database to 1.1"; | ||
|
|
||
| /// <summary> | ||
| /// Upgrade process | ||
| /// </summary> | ||
| /// <param name="database"></param> | ||
| /// <param name="serviceProvider"></param> | ||
| /// <returns></returns> | ||
| public bool UpgradeProcess(IServiceProvider serviceProvider) | ||
| { | ||
| var repository = serviceProvider.GetRequiredService<IRepository<GrandNodeVersion>>(); | ||
|
|
||
| var dbversion = repository.Table.FirstOrDefault(); | ||
| dbversion!.DataBaseVersion = $"{GrandVersion.SupportedDBVersion}"; | ||
| repository.Update(dbversion); | ||
|
|
||
| return true; | ||
| } | ||
| } | ||
| public override Guid Identity => new("6BDB7093-4C31-4D78-9604-58188DF728D3"); | ||
| } |
33 changes: 4 additions & 29 deletions
33
src/Modules/Grand.Module.Migration/Migrations/2.0/MigrationUpgradeDbVersion_20.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,10 @@ | ||
| using Grand.Data; | ||
| using Grand.Domain.Common; | ||
| using Grand.Infrastructure; | ||
| using Grand.Infrastructure.Migrations; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| namespace Grand.Module.Migration.Migrations._2._0; | ||
|
|
||
| public class MigrationUpgradeDbVersion_20 : IMigration | ||
| public class MigrationUpgradeDbVersion_20 : MigrationUpgradeDbVersionBase | ||
| { | ||
| public int Priority => 0; | ||
| public override DbVersion Version => new(2, 0); | ||
|
|
||
| public DbVersion Version => new(2, 0); | ||
|
|
||
| public Guid Identity => new("AEC3CF1F-4443-474A-B932-4F91D08C8F61"); | ||
|
|
||
| public string Name => "Upgrade version of the database to 2.0"; | ||
|
|
||
| /// <summary> | ||
| /// Upgrade process | ||
| /// </summary> | ||
| /// <param name="database"></param> | ||
| /// <param name="serviceProvider"></param> | ||
| /// <returns></returns> | ||
| public bool UpgradeProcess(IServiceProvider serviceProvider) | ||
| { | ||
| var repository = serviceProvider.GetRequiredService<IRepository<GrandNodeVersion>>(); | ||
|
|
||
| var dbversion = repository.Table.FirstOrDefault(); | ||
| dbversion!.DataBaseVersion = $"{GrandVersion.SupportedDBVersion}"; | ||
| repository.Update(dbversion); | ||
|
|
||
| return true; | ||
| } | ||
| } | ||
| public override Guid Identity => new("AEC3CF1F-4443-474A-B932-4F91D08C8F61"); | ||
| } |
33 changes: 4 additions & 29 deletions
33
src/Modules/Grand.Module.Migration/Migrations/2.1/MigrationUpgradeDbVersion_21.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,10 @@ | ||
| using Grand.Data; | ||
| using Grand.Domain.Common; | ||
| using Grand.Infrastructure; | ||
| using Grand.Infrastructure.Migrations; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| namespace Grand.Module.Migration.Migrations._2._1; | ||
|
|
||
| public class MigrationUpgradeDbVersion_21 : IMigration | ||
| public class MigrationUpgradeDbVersion_21 : MigrationUpgradeDbVersionBase | ||
| { | ||
| public int Priority => 0; | ||
| public override DbVersion Version => new(2, 1); | ||
|
|
||
| public DbVersion Version => new(2, 1); | ||
|
|
||
| public Guid Identity => new("EA674DAA-66B2-4F21-9C68-008ACE752FBD"); | ||
|
|
||
| public string Name => "Upgrade version of the database to 2.1"; | ||
|
|
||
| /// <summary> | ||
| /// Upgrade process | ||
| /// </summary> | ||
| /// <param name="database"></param> | ||
| /// <param name="serviceProvider"></param> | ||
| /// <returns></returns> | ||
| public bool UpgradeProcess(IServiceProvider serviceProvider) | ||
| { | ||
| var repository = serviceProvider.GetRequiredService<IRepository<GrandNodeVersion>>(); | ||
|
|
||
| var dbversion = repository.Table.FirstOrDefault(); | ||
| dbversion!.DataBaseVersion = $"{GrandVersion.SupportedDBVersion}"; | ||
| repository.Update(dbversion); | ||
|
|
||
| return true; | ||
| } | ||
| } | ||
| public override Guid Identity => new("EA674DAA-66B2-4F21-9C68-008ACE752FBD"); | ||
| } |
33 changes: 4 additions & 29 deletions
33
src/Modules/Grand.Module.Migration/Migrations/2.2/MigrationUpgradeDbVersion_22.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,10 @@ | ||
| using Grand.Data; | ||
| using Grand.Domain.Common; | ||
| using Grand.Infrastructure; | ||
| using Grand.Infrastructure.Migrations; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| namespace Grand.Module.Migration.Migrations._2._2; | ||
|
|
||
| public class MigrationUpgradeDbVersion_22 : IMigration | ||
| public class MigrationUpgradeDbVersion_22 : MigrationUpgradeDbVersionBase | ||
| { | ||
| public int Priority => 0; | ||
| public override DbVersion Version => new(2, 2); | ||
|
|
||
| public DbVersion Version => new(2, 2); | ||
|
|
||
| public Guid Identity => new("9B9FD138-7E67-44AA-913B-273F3D5B5DE9"); | ||
|
|
||
| public string Name => "Upgrade version of the database to 2.2"; | ||
|
|
||
| /// <summary> | ||
| /// Upgrade process | ||
| /// </summary> | ||
| /// <param name="database"></param> | ||
| /// <param name="serviceProvider"></param> | ||
| /// <returns></returns> | ||
| public bool UpgradeProcess(IServiceProvider serviceProvider) | ||
| { | ||
| var repository = serviceProvider.GetRequiredService<IRepository<GrandNodeVersion>>(); | ||
|
|
||
| var dbversion = repository.Table.FirstOrDefault(); | ||
| dbversion!.DataBaseVersion = $"{GrandVersion.SupportedDBVersion}"; | ||
| repository.Update(dbversion); | ||
|
|
||
| return true; | ||
| } | ||
| } | ||
| public override Guid Identity => new("9B9FD138-7E67-44AA-913B-273F3D5B5DE9"); | ||
| } |
34 changes: 4 additions & 30 deletions
34
src/Modules/Grand.Module.Migration/Migrations/2.3/MigrationUpgradeDbVersion_23.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,36 +1,10 @@ | ||
| using Grand.Data; | ||
| using Grand.Domain.Common; | ||
| using Grand.Infrastructure; | ||
| using Grand.Infrastructure.Migrations; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| namespace Grand.Module.Migration.Migrations._2._3; | ||
|
|
||
| public class MigrationUpgradeDbVersion_23 : IMigration | ||
| public class MigrationUpgradeDbVersion_23 : MigrationUpgradeDbVersionBase | ||
| { | ||
| public int Priority => 0; | ||
| public override DbVersion Version => new(2, 3); | ||
|
|
||
| public DbVersion Version => new(2, 3); | ||
|
|
||
| public Guid Identity => new("689E5BFA-7229-41A5-AF48-07CB58C0D608"); | ||
|
|
||
| public string Name => "Upgrade version of the database to 2.3"; | ||
|
|
||
| /// <summary> | ||
| /// Upgrade process | ||
| /// </summary> | ||
| /// <param name="database"></param> | ||
| /// <param name="serviceProvider"></param> | ||
| /// <returns></returns> | ||
| public bool UpgradeProcess(IServiceProvider serviceProvider) | ||
| { | ||
| var repository = serviceProvider.GetRequiredService<IRepository<GrandNodeVersion>>(); | ||
|
|
||
| var dbversion = repository.Table.FirstOrDefault(); | ||
| dbversion!.InstalledVersion = $"{GrandVersion.SupportedDBVersion}"; | ||
| dbversion!.DataBaseVersion = $"{GrandVersion.SupportedDBVersion}"; | ||
| repository.Update(dbversion); | ||
|
|
||
| return true; | ||
| } | ||
| } | ||
| public override Guid Identity => new("689E5BFA-7229-41A5-AF48-07CB58C0D608"); | ||
| } |
31 changes: 3 additions & 28 deletions
31
src/Modules/Grand.Module.Migration/Migrations/2.4/MigrationUpgradeDbVersion_24.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,10 @@ | ||
| using Grand.Data; | ||
| using Grand.Domain.Common; | ||
| using Grand.Infrastructure; | ||
| using Grand.Infrastructure.Migrations; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| namespace Grand.Module.Migration.Migrations._2._4; | ||
|
|
||
| public class MigrationUpgradeDbVersion_24 : IMigration | ||
| public class MigrationUpgradeDbVersion_24 : MigrationUpgradeDbVersionBase | ||
| { | ||
| public int Priority => 0; | ||
| public override DbVersion Version => new(2, 4); | ||
|
|
||
| public DbVersion Version => new(2, 4); | ||
|
|
||
| public Guid Identity => new("A1B2C3D4-E5F6-7890-ABCD-EF1234567890"); | ||
|
|
||
| public string Name => "Upgrade version of the database to 2.4"; | ||
|
|
||
| /// <summary> | ||
| /// Upgrade process | ||
| /// </summary> | ||
| /// <param name="serviceProvider"></param> | ||
| /// <returns></returns> | ||
| public bool UpgradeProcess(IServiceProvider serviceProvider) | ||
| { | ||
| var repository = serviceProvider.GetRequiredService<IRepository<GrandNodeVersion>>(); | ||
|
|
||
| var dbversion = repository.Table.FirstOrDefault(); | ||
| dbversion!.InstalledVersion = $"{GrandVersion.SupportedDBVersion}"; | ||
| dbversion!.DataBaseVersion = $"{GrandVersion.SupportedDBVersion}"; | ||
| repository.Update(dbversion); | ||
|
|
||
| return true; | ||
| } | ||
| public override Guid Identity => new("A1B2C3D4-E5F6-7890-ABCD-EF1234567890"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/Modules/Grand.Module.Migration/Migrations/MigrationUpgradeDbVersionBase.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| using Grand.Data; | ||
| using Grand.Domain.Common; | ||
| using Grand.Infrastructure.Migrations; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| namespace Grand.Module.Migration.Migrations; | ||
|
|
||
| /// <summary> | ||
| /// Records <see cref="Version" /> as the version the database has reached. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Runs last within its version - see <see cref="IMigrationVersionStamp" />. | ||
| /// </remarks> | ||
| public abstract class MigrationUpgradeDbVersionBase : IMigrationVersionStamp | ||
| { | ||
| public int Priority => 0; | ||
|
|
||
| public abstract DbVersion Version { get; } | ||
|
|
||
| public abstract Guid Identity { get; } | ||
|
|
||
| public string Name => $"Upgrade version of the database to {Version}"; | ||
|
|
||
| /// <summary> | ||
| /// Upgrade process | ||
| /// </summary> | ||
| /// <param name="serviceProvider"></param> | ||
| /// <returns></returns> | ||
| public bool UpgradeProcess(IServiceProvider serviceProvider) | ||
| { | ||
| var repository = serviceProvider.GetRequiredService<IRepository<GrandNodeVersion>>(); | ||
|
|
||
| var dbversion = repository.Table.FirstOrDefault(); | ||
| if (dbversion == null) | ||
| return false; | ||
|
|
||
| //stamp the version this migration closes, not the version the build supports - stamping | ||
| //the latest supported version here makes every migration in between unreachable | ||
| dbversion.InstalledVersion = Version.ToString(); | ||
| dbversion.DataBaseVersion = Version.ToString(); | ||
| repository.Update(dbversion); | ||
|
|
||
| return true; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.