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

[release/9.0-staging] Don't throw PendingModelChangesWarning when applying a specific migration #35353

Open
wants to merge 1 commit into
base: release/9.0-staging
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
10 changes: 5 additions & 5 deletions src/EFCore.Relational/Migrations/Internal/Migrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System.Transactions;
using Microsoft.EntityFrameworkCore.Diagnostics.Internal;
using Microsoft.EntityFrameworkCore.Metadata.Internal;

namespace Microsoft.EntityFrameworkCore.Migrations.Internal;

Expand Down Expand Up @@ -94,7 +93,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 +218,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 +348,7 @@ await _migrationCommandExecutor.ExecuteNonQueryAsync(
}
}

private void ValidateMigrations(bool useTransaction)
private void ValidateMigrations(bool useTransaction, string? targetMigration)
{
if (!useTransaction
&& _executionStrategy.RetriesOnFailure)
Expand All @@ -365,7 +364,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
Original file line number Diff line number Diff line change
Expand Up @@ -816,8 +816,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