Skip to content

The planner's Lost/RebuildAround precedence and two KeepInPlace rules are held by no test #169

Open

Description

@CaffeinatedCoder

Found by the pre-tag review of 948496a..0ee827d (the review for v11.0.0-preview.1). Each change below was applied to the planner on its own, and the offline suites (kernel, PostgreSQL, second provider) still passed. No live test covers them either.

1. Lost against RebuildAround

SchemaOperationPlanner (Weight, around line 384) gives RebuildAround more weight than Lost, so when one migration does both to the same object, rebuilding around it wins. Seed: Impact.Lost => 4. No test fails. Every drop test in PgExclusionLiveTests drops one column.

Scenario: a migration drops both an element column (Lost) and a column only the condition reads (RebuildAround) of the same exclusion constraint. With the order reversed, the constraint is not dropped before EF Core's operations. The migration then fails with 2BP01 or happens to work, depending on which column EF Core drops first. That failure is loud, not silent.

A test that holds it (it passes on 0ee827d and fails under the seed):

public sealed class WithoutRoleAndRevocation : ITestModel
{
    public static void Build(ModelBuilder modelBuilder)
    {
        var grants = modelBuilder.Entity<RoleGrant>().ToTable("role_grants");
        grants.Ignore(x => x.RoleId);
        grants.Ignore(x => x.RevokedOn);
        grants.DeclarePostgres(pg =>
            [pg.Exclusion(pg.Equal(x => x.GranteeId).Overlaps(x => x.Period), deferral: Deferral.InitiallyDeferred, name: Models.Name)]);
    }
}

[TestMethod]
public void The_answer_that_asks_most_decides_RebuildAround_over_Lost()
{
    var shape = Contexts.Diff<Models.Scheduling, WithoutRoleAndRevocation>().Shape();
    Assert.AreEqual("ALTER TABLE role_grants DROP CONSTRAINT ex_role_grant_active_period;",
        shape.SkipWhile(s => s.StartsWith("CREATE EXTENSION")).First());
}

It should also get a row in PgExclusionLiveTests.

2. KeepInPlace: a dropped BeforeTables object still holds its name

Held keeps the claims of a dropped object whose contributor is BeforeTables, since such an object is dropped after EF Core's operations (if (dropped.Contains(source) && !source.Contributor.Placement.IsBeforeTables) continue;). Seed: take out && !…IsBeforeTables. No test fails, because no test contributor is BeforeTables. If this broke, a rename in place would collide when the migration is applied, which is loud.

3. KeepInPlace: held.AddRange(takes)

Seed: remove the line that records a change's new names after it is written. No test fails. Two renames in one migration that take one name are already refused by the own-model name check (NameClaims.Require), so the line cannot be reached today. Either hold it with a test that gets around that check, or say in a comment why it is defensive only.

Does it block preview.1?

No. All three are missing tests for rules that hold today, and each failure they would let through is loud.

Activity

  1. added this to the 11.0.0 milestone on Nov 17, 2026
  2. added
    tests
    package/core
    severity/low
    area/migrations
    on Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/migrationspackage/coreseverity/lowtests

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions