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

Don't throw PendingModelChangesWarning when applying a specific migration #35343

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/EFCore.Relational/Migrations/Internal/Migrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public Migrator(
public virtual void Migrate(string? targetMigration)
{
var useTransaction = _connection.CurrentTransaction is null;
ValidateMigrations(useTransaction);
ValidateMigrations(useTransaction, targetMigration);

using var transactionScope = new TransactionScope(TransactionScopeOption.Suppress, TransactionScopeAsyncFlowOption.Enabled);

Expand Down Expand Up @@ -219,7 +219,7 @@ public virtual async Task MigrateAsync(
CancellationToken cancellationToken = default)
{
var useTransaction = _connection.CurrentTransaction is null;
ValidateMigrations(useTransaction);
ValidateMigrations(useTransaction, targetMigration);

using var transactionScope = new TransactionScope(TransactionScopeOption.Suppress, TransactionScopeAsyncFlowOption.Enabled);

Expand Down Expand Up @@ -349,7 +349,7 @@ await _migrationCommandExecutor.ExecuteNonQueryAsync(
}
}

private void ValidateMigrations(bool useTransaction)
private void ValidateMigrations(bool useTransaction, string? targetMigration)
{
if (!useTransaction
&& _executionStrategy.RetriesOnFailure)
Expand All @@ -365,7 +365,8 @@ private void ValidateMigrations(bool useTransaction)
{
_logger.ModelSnapshotNotFound(this, _migrationsAssembly);
}
else if (RelationalResources.LogPendingModelChanges(_logger).WarningBehavior != WarningBehavior.Ignore
else if (targetMigration == null
&& RelationalResources.LogPendingModelChanges(_logger).WarningBehavior != WarningBehavior.Ignore
&& HasPendingModelChanges())
{
var modelSource = (ModelSource)_currentContext.Context.GetService<IModelSource>();
Expand Down
18 changes: 9 additions & 9 deletions test/EFCore.Specification.Tests/DataBindingTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,32 +281,32 @@ public virtual void Remove_detached_entity_from_LocalView(bool toObservableColle
Assert.Equal(2, local.ToList().Count);

Assert.True(local.Contains(driver1));
Assert.True(localView.Contains(driver1));
Assert.Contains(driver1, localView);
Assert.True(local.Contains(driver2));
Assert.True(localView.Contains(driver2));
Assert.Contains(driver2, localView);
Assert.False(local.Contains(driver3));
Assert.False(localView.Contains(driver3));
Assert.DoesNotContain(driver3, localView);

context.Entry(driver3);

Assert.True(local.Contains(driver1));
Assert.True(localView.Contains(driver1));
Assert.Contains(driver1, localView);
Assert.True(local.Contains(driver2));
Assert.True(localView.Contains(driver2));
Assert.Contains(driver2, localView);
Assert.False(local.Contains(driver3));
Assert.False(localView.Contains(driver3));
Assert.DoesNotContain(driver3, localView);

local.Remove(driver3);

Assert.Equal(2, local.Count);
Assert.Equal(2, local.ToList().Count);

Assert.True(local.Contains(driver1));
Assert.True(localView.Contains(driver1));
Assert.Contains(driver1, localView);
Assert.True(local.Contains(driver2));
Assert.True(localView.Contains(driver2));
Assert.Contains(driver2, localView);
Assert.False(local.Contains(driver3));
Assert.False(localView.Contains(driver3));
Assert.DoesNotContain(driver3, localView);
}

[ConditionalTheory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -807,8 +807,7 @@ public async Task Empty_Migration_Creates_Database()
{
using var context = new BloggingContext(
Fixture.TestStore.AddProviderOptions(
new DbContextOptionsBuilder().EnableServiceProviderCaching(false))
.ConfigureWarnings(e => e.Log(RelationalEventId.PendingModelChangesWarning)).Options);
new DbContextOptionsBuilder().EnableServiceProviderCaching(false)).Options);

context.Database.EnsureDeleted();
GiveMeSomeTime(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
b =>
{
b.OwnsOne(x => x.OwnedReferenceRoot).ToJson("json_reference_custom_naming").HasColumnType("json");
;
b.OwnsMany(x => x.OwnedCollectionRoot).HasColumnType("json").ToJson("json_collection_custom_naming");
});

Expand Down