From 43aeb620fd3c39dd83e7754c8fb1634c1620fdff Mon Sep 17 00:00:00 2001 From: Brice Lambson Date: Tue, 18 Jul 2023 09:49:39 -0700 Subject: [PATCH] Clean up PR #31164 --- .../Design/Internal/MigrationsOperations.cs | 2 +- src/EFCore.Design/Design/OperationExecutor.cs | 12 ++++++------ .../Extensions/RelationalDatabaseFacadeExtensions.cs | 2 +- .../MigrationsHasPendingModelChangesCommand.cs | 2 +- src/ef/IOperationExecutor.cs | 2 +- src/ef/OperationExecutorBase.cs | 4 ++-- .../RelationalDatabaseFacadeExtensionsTest.cs | 10 +++------- 7 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/EFCore.Design/Design/Internal/MigrationsOperations.cs b/src/EFCore.Design/Design/Internal/MigrationsOperations.cs index 3f105e7ba87..e597ec6afd5 100644 --- a/src/EFCore.Design/Design/Internal/MigrationsOperations.cs +++ b/src/EFCore.Design/Design/Internal/MigrationsOperations.cs @@ -249,7 +249,7 @@ public virtual MigrationFiles RemoveMigration( /// 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 CheckPendingMigrations(string? contextType) + public virtual void HasPendingModelChanges(string? contextType) { using var context = _contextOperations.CreateContext(contextType); diff --git a/src/EFCore.Design/Design/OperationExecutor.cs b/src/EFCore.Design/Design/OperationExecutor.cs index 715ecfe5421..046be5f92a5 100644 --- a/src/EFCore.Design/Design/OperationExecutor.cs +++ b/src/EFCore.Design/Design/OperationExecutor.cs @@ -686,10 +686,10 @@ private string ScriptDbContextImpl(string? contextType) /// /// Represents an operation to check if there are any pending migrations. /// - public class CheckPendingMigrations : OperationBase + public class HasPendingModelChanges : OperationBase { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// The arguments supported by are: @@ -698,7 +698,7 @@ public class CheckPendingMigrations : OperationBase /// The operation executor. /// The . /// The operation arguments. - public CheckPendingMigrations( + public HasPendingModelChanges( OperationExecutor executor, IOperationResultHandler resultHandler, IDictionary args) @@ -709,12 +709,12 @@ public CheckPendingMigrations( var contextType = (string?)args["contextType"]; - Execute(() => executor.CheckPendingMigrationsImpl(contextType)); + Execute(() => executor.HasPendingModelChangesImpl(contextType)); } } - private void CheckPendingMigrationsImpl(string? contextType) - => MigrationsOperations.CheckPendingMigrations(contextType); + private void HasPendingModelChangesImpl(string? contextType) + => MigrationsOperations.HasPendingModelChanges(contextType); /// diff --git a/src/EFCore.Relational/Extensions/RelationalDatabaseFacadeExtensions.cs b/src/EFCore.Relational/Extensions/RelationalDatabaseFacadeExtensions.cs index 694d0f7e285..93ef6883761 100644 --- a/src/EFCore.Relational/Extensions/RelationalDatabaseFacadeExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalDatabaseFacadeExtensions.cs @@ -955,7 +955,7 @@ public static bool IsRelational(this DatabaseFacade databaseFacade) /// /// Returns if the model has pending changes to be applied. /// - /// Tbe facade from . + /// The facade from . /// /// if the database model has pending changes. /// if a new migration has to be added. diff --git a/src/ef/Commands/MigrationsHasPendingModelChangesCommand.cs b/src/ef/Commands/MigrationsHasPendingModelChangesCommand.cs index 57068b8e53e..bdbd2db8b6a 100644 --- a/src/ef/Commands/MigrationsHasPendingModelChangesCommand.cs +++ b/src/ef/Commands/MigrationsHasPendingModelChangesCommand.cs @@ -9,7 +9,7 @@ protected override int Execute(string[] args) { using var executor = CreateExecutor(args); - executor.CheckPendingMigrations(Context!.Value()); + executor.HasPendingModelChanges(Context!.Value()); return base.Execute(args); } diff --git a/src/ef/IOperationExecutor.cs b/src/ef/IOperationExecutor.cs index 432c2df68f5..e77caaab7c7 100644 --- a/src/ef/IOperationExecutor.cs +++ b/src/ef/IOperationExecutor.cs @@ -37,5 +37,5 @@ IDictionary ScaffoldContext( string ScriptMigration(string? fromMigration, string? toMigration, bool idempotent, bool noTransactions, string? contextType); string ScriptDbContext(string? contextType); - void CheckPendingMigrations(string? contextType); + void HasPendingModelChanges(string? contextType); } diff --git a/src/ef/OperationExecutorBase.cs b/src/ef/OperationExecutorBase.cs index a4fcd85546c..8e578bebc8f 100644 --- a/src/ef/OperationExecutorBase.cs +++ b/src/ef/OperationExecutorBase.cs @@ -207,8 +207,8 @@ public string ScriptDbContext(string? contextType) "ScriptDbContext", new Dictionary { ["contextType"] = contextType }); - public void CheckPendingMigrations(string? contextType) + public void HasPendingModelChanges(string? contextType) => InvokeOperation( - "CheckPendingMigrations", + "HasPendingModelChanges", new Dictionary { ["contextType"] = contextType }); } diff --git a/test/EFCore.Relational.Tests/RelationalDatabaseFacadeExtensionsTest.cs b/test/EFCore.Relational.Tests/RelationalDatabaseFacadeExtensionsTest.cs index dc0dcec8f1b..5f1a269d466 100644 --- a/test/EFCore.Relational.Tests/RelationalDatabaseFacadeExtensionsTest.cs +++ b/test/EFCore.Relational.Tests/RelationalDatabaseFacadeExtensionsTest.cs @@ -3,7 +3,6 @@ using System.Transactions; using Microsoft.EntityFrameworkCore.InMemory.Storage.Internal; -using Microsoft.EntityFrameworkCore.TestModels.UpdatesModel; using Microsoft.EntityFrameworkCore.TestUtilities.FakeProvider; using IsolationLevel = System.Data.IsolationLevel; @@ -275,14 +274,11 @@ public void HasPendingModelChanges_has_migrations_and_no_new_context_changes_ret { var fakeModelSnapshot = new FakeModelSnapshot(builder => { - // TODO: This seems fragile, what should I do? - builder.HasAnnotation("ProductVersion", "8.0.0-dev"); - builder.Entity("Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensionsTests.TestDbContext.Simple", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("default_int_mapping"); b.HasKey("Id"); @@ -291,7 +287,7 @@ public void HasPendingModelChanges_has_migrations_and_no_new_context_changes_ret }); var migrationsAssembly = new FakeIMigrationsAssembly { - ModelSnapshot = null, + ModelSnapshot = fakeModelSnapshot, Migrations = new Dictionary(), }; @@ -302,7 +298,7 @@ public void HasPendingModelChanges_has_migrations_and_no_new_context_changes_ret var testContext = new TestDbContext(contextOptions); - Assert.True(testContext.Database.HasPendingModelChanges()); + Assert.False(testContext.Database.HasPendingModelChanges()); } private class TestDbContext : DbContext