From b6fbc5565c56becc045be3002e6b3934d1bae6a5 Mon Sep 17 00:00:00 2001 From: Andriy Svyryd Date: Thu, 1 Aug 2024 10:43:48 -0700 Subject: [PATCH] Change IMigrator.Migrate signature --- .../Design/Internal/MigrationsOperations.cs | 2 +- .../Migrations/Design/MigrationsScaffolder.cs | 2 +- .../RelationalDatabaseFacadeExtensions.cs | 4 ++-- src/EFCore.Relational/Migrations/IMigrator.cs | 16 +++++++------- .../Migrations/IMigratorPlugin.cs | 10 ++++----- .../Migrations/Internal/Migrator.cs | 4 ++-- .../MigrationsInfrastructureTestBase.cs | 22 +++++++++---------- .../Infrastructure/RelationalEventIdTest.cs | 6 ++--- 8 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/EFCore.Design/Design/Internal/MigrationsOperations.cs b/src/EFCore.Design/Design/Internal/MigrationsOperations.cs index e6f314769e9..419d658cd2e 100644 --- a/src/EFCore.Design/Design/Internal/MigrationsOperations.cs +++ b/src/EFCore.Design/Design/Internal/MigrationsOperations.cs @@ -221,7 +221,7 @@ public virtual void UpdateDatabase( var migrator = services.GetRequiredService(); - migrator.Migrate(targetMigration); + migrator.Migrate(targetMigration: targetMigration); } _reporter.WriteInformation(DesignStrings.Done); diff --git a/src/EFCore.Design/Migrations/Design/MigrationsScaffolder.cs b/src/EFCore.Design/Migrations/Design/MigrationsScaffolder.cs index cd58c96f169..a64419911ad 100644 --- a/src/EFCore.Design/Migrations/Design/MigrationsScaffolder.cs +++ b/src/EFCore.Design/Migrations/Design/MigrationsScaffolder.cs @@ -285,7 +285,7 @@ public virtual MigrationFiles RemoveMigration( if (force) { Dependencies.Migrator.Migrate( - migrations.Count > 1 + targetMigration: migrations.Count > 1 ? migrations[^2].GetId() : Migration.InitialDatabase); } diff --git a/src/EFCore.Relational/Extensions/RelationalDatabaseFacadeExtensions.cs b/src/EFCore.Relational/Extensions/RelationalDatabaseFacadeExtensions.cs index a5ccf7f3fc3..e355e7a7c23 100644 --- a/src/EFCore.Relational/Extensions/RelationalDatabaseFacadeExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalDatabaseFacadeExtensions.cs @@ -148,7 +148,7 @@ public static void Migrate( Action? seed, string? targetMigration = null, TimeSpan? lockTimeout = null) - => databaseFacade.GetRelationalService().Migrate(targetMigration, seed, lockTimeout); + => databaseFacade.GetRelationalService().Migrate(seed, targetMigration, lockTimeout); /// /// Asynchronously applies any pending migrations for the context to the database. Will create the database @@ -213,7 +213,7 @@ public static Task MigrateAsync( string? targetMigration = null, TimeSpan? lockTimeout = null, CancellationToken cancellationToken = default) - => databaseFacade.GetRelationalService().MigrateAsync(targetMigration, seed, lockTimeout, cancellationToken); + => databaseFacade.GetRelationalService().MigrateAsync(seed, targetMigration, lockTimeout, cancellationToken); /// /// Executes the given SQL against the database and returns the number of rows affected. diff --git a/src/EFCore.Relational/Migrations/IMigrator.cs b/src/EFCore.Relational/Migrations/IMigrator.cs index 69225454347..0b02cbe7df3 100644 --- a/src/EFCore.Relational/Migrations/IMigrator.cs +++ b/src/EFCore.Relational/Migrations/IMigrator.cs @@ -26,12 +26,12 @@ public interface IMigrator /// Migrates the database to either a specified target migration or up to the latest /// migration that exists in the . /// - /// - /// The target migration to migrate the database to, or to migrate to the latest. - /// /// /// The optional seed method to run after migrating the database. It will be invoked even if no migrations were applied. /// + /// + /// The target migration to migrate the database to, or to migrate to the latest. + /// /// /// The maximum amount of time that the migration lock should be held. Unless a catastrophic failure occurs, the /// lock is released when the migration operation completes. @@ -41,18 +41,18 @@ public interface IMigrator /// [RequiresUnreferencedCode("Migration generation currently isn't compatible with trimming")] [RequiresDynamicCode("Migrations operations are not supported with NativeAOT")] - void Migrate(string? targetMigration = null, Action? seed = null, TimeSpan? lockTimeout = null); + void Migrate(Action? seed = null, string? targetMigration = null, TimeSpan? lockTimeout = null); /// /// Migrates the database to either a specified target migration or up to the latest /// migration that exists in the . /// - /// - /// The target migration to migrate the database to, or to migrate to the latest. - /// /// /// The optional seed method to run after migrating the database. It will be invoked even if no migrations were applied. /// + /// + /// The target migration to migrate the database to, or to migrate to the latest. + /// /// /// The maximum amount of time that the migration lock should be held. Unless a catastrophic failure occurs, the /// lock is released when the migration operation completes. @@ -66,8 +66,8 @@ public interface IMigrator [RequiresUnreferencedCode("Migration generation currently isn't compatible with trimming")] [RequiresDynamicCode("Migrations operations are not supported with NativeAOT")] Task MigrateAsync( - string? targetMigration = null, Func? seed = null, + string? targetMigration = null, TimeSpan? lockTimeout = null, CancellationToken cancellationToken = default); diff --git a/src/EFCore.Relational/Migrations/IMigratorPlugin.cs b/src/EFCore.Relational/Migrations/IMigratorPlugin.cs index 9c1409a9cc0..ae06c4d968e 100644 --- a/src/EFCore.Relational/Migrations/IMigratorPlugin.cs +++ b/src/EFCore.Relational/Migrations/IMigratorPlugin.cs @@ -6,7 +6,7 @@ namespace Microsoft.EntityFrameworkCore.Migrations; /// /// /// A service on the EF internal service provider that allows providers or extensions to execute logic -/// after is called. +/// after is called. /// /// /// This type is typically used by providers or extensions. It is generally not used in application code. @@ -20,7 +20,7 @@ namespace Microsoft.EntityFrameworkCore.Migrations; public interface IMigratorPlugin { /// - /// Called by before applying the migrations. + /// Called by before applying the migrations. /// /// The that is being migrated. /// The that contains the result of the migrations application. @@ -30,7 +30,7 @@ public interface IMigratorPlugin void Migrating(DbContext context, IMigratorData data); /// - /// Called by before applying the migrations. + /// Called by before applying the migrations. /// /// The that is being migrated. /// The that contains the result of the migrations application. @@ -46,7 +46,7 @@ Task MigratingAsync( CancellationToken cancellationToken = default); /// - /// Called by after applying the migrations, but before the seeding action. + /// Called by after applying the migrations, but before the seeding action. /// /// The that is being migrated. /// The that contains the result of the migrations application. @@ -56,7 +56,7 @@ Task MigratingAsync( void Migrated(DbContext context, IMigratorData data); /// - /// Called by after applying the migrations, but before the seeding action. + /// Called by after applying the migrations, but before the seeding action. /// /// The that is being migrated. /// The that contains the result of the migrations application. diff --git a/src/EFCore.Relational/Migrations/Internal/Migrator.cs b/src/EFCore.Relational/Migrations/Internal/Migrator.cs index 055fa992ac6..4012a1a7a53 100644 --- a/src/EFCore.Relational/Migrations/Internal/Migrator.cs +++ b/src/EFCore.Relational/Migrations/Internal/Migrator.cs @@ -80,7 +80,7 @@ public Migrator( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual void Migrate(string? targetMigration, Action? seed, TimeSpan? lockTimeout) + public virtual void Migrate(Action? seed, string? targetMigration, TimeSpan? lockTimeout) { if (RelationalResources.LogPendingModelChanges(_logger).WarningBehavior != WarningBehavior.Ignore && HasPendingModelChanges()) @@ -147,8 +147,8 @@ public virtual void Migrate(string? targetMigration, Action public virtual async Task MigrateAsync( - string? targetMigration, Func? seed, + string? targetMigration, TimeSpan? lockTimeout = null, CancellationToken cancellationToken = default) { diff --git a/test/EFCore.Relational.Specification.Tests/Migrations/MigrationsInfrastructureTestBase.cs b/test/EFCore.Relational.Specification.Tests/Migrations/MigrationsInfrastructureTestBase.cs index 8aac3a0b618..f5baf42669c 100644 --- a/test/EFCore.Relational.Specification.Tests/Migrations/MigrationsInfrastructureTestBase.cs +++ b/test/EFCore.Relational.Specification.Tests/Migrations/MigrationsInfrastructureTestBase.cs @@ -161,7 +161,7 @@ public virtual void Can_apply_one_migration() GiveMeSomeTime(db); var migrator = db.GetService(); - migrator.Migrate("Migration1"); + migrator.Migrate(targetMigration: "Migration1"); var history = db.GetService(); Assert.Collection( @@ -181,8 +181,8 @@ public virtual void Can_revert_all_migrations() GiveMeSomeTime(db); var migrator = db.GetService(); - migrator.Migrate("Migration5"); - migrator.Migrate(Migration.InitialDatabase); + migrator.Migrate(targetMigration: "Migration5"); + migrator.Migrate(targetMigration: Migration.InitialDatabase); var history = db.GetService(); Assert.Empty(history.GetAppliedMigrations()); @@ -197,8 +197,8 @@ public virtual void Can_revert_one_migrations() GiveMeSomeTime(db); var migrator = db.GetService(); - migrator.Migrate("Migration5"); - migrator.Migrate("Migration4"); + migrator.Migrate(targetMigration: "Migration5"); + migrator.Migrate(targetMigration: "Migration4"); var history = db.GetService(); Assert.Collection( @@ -221,7 +221,7 @@ public virtual void Can_apply_one_migration_in_parallel() { using var context = Fixture.CreateContext(); var migrator = context.GetService(); - migrator.Migrate("Migration1"); + migrator.Migrate(targetMigration: "Migration1"); }); var history = db.GetService(); @@ -242,7 +242,7 @@ await Parallel.ForAsync(0, Environment.ProcessorCount, async (i, _) => { using var context = Fixture.CreateContext(); var migrator = context.GetService(); - await migrator.MigrateAsync("Migration1"); + await migrator.MigrateAsync(targetMigration: "Migration1"); }); var history = db.GetService(); @@ -257,13 +257,13 @@ public virtual void Can_apply_second_migration_in_parallel() using var db = Fixture.CreateContext(); db.Database.EnsureDeleted(); GiveMeSomeTime(db); - db.GetService().Migrate("Migration1"); + db.GetService().Migrate(targetMigration: "Migration1"); Parallel.For(0, Environment.ProcessorCount, i => { using var context = Fixture.CreateContext(); var migrator = context.GetService(); - migrator.Migrate("Migration2"); + migrator.Migrate(targetMigration: "Migration2"); }); var history = db.GetService(); @@ -279,13 +279,13 @@ public virtual async Task Can_apply_second_migration_in_parallel_async() using var db = Fixture.CreateContext(); await db.Database.EnsureDeletedAsync(); await GiveMeSomeTimeAsync(db); - await db.GetService().MigrateAsync("Migration1"); + await db.GetService().MigrateAsync(targetMigration: "Migration1"); await Parallel.ForAsync(0, Environment.ProcessorCount, async (i, _) => { using var context = Fixture.CreateContext(); var migrator = context.GetService(); - await migrator.MigrateAsync("Migration2"); + await migrator.MigrateAsync(targetMigration: "Migration2"); }); var history = db.GetService(); diff --git a/test/EFCore.Relational.Tests/Infrastructure/RelationalEventIdTest.cs b/test/EFCore.Relational.Tests/Infrastructure/RelationalEventIdTest.cs index 79caba6efc0..6e2a764b005 100644 --- a/test/EFCore.Relational.Tests/Infrastructure/RelationalEventIdTest.cs +++ b/test/EFCore.Relational.Tests/Infrastructure/RelationalEventIdTest.cs @@ -149,11 +149,11 @@ public string GenerateScript( MigrationsSqlGenerationOptions options = MigrationsSqlGenerationOptions.Default) => throw new NotImplementedException(); - public void Migrate(string targetMigration, Action seed, TimeSpan? lockTimeout) + public void Migrate(Action seed, string targetMigration, TimeSpan? lockTimeout) => throw new NotImplementedException(); - public Task MigrateAsync(string targetMigration, - Func seed, + public Task MigrateAsync(Func seed, + string targetMigration, TimeSpan? lockTimeout, CancellationToken cancellationToken = default) => throw new NotImplementedException();