Skip to content

fix: the consumer's model is told by reference, not by where it stands in a diff - #122

Merged
CaffeinatedCoder merged 1 commit into
mainfrom
fix/the-consumers-model-by-reference
Nov 14, 2026
Merged

CaffeinatedCoder merged 1 commit into
mainfrom
fix/the-consumers-model-by-reference

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #98

Problem

A project moves from EFCore.ComplexIndexes 5.x, declares the same exclusion constraints with DeclarePostgres, and its first migrations add holds one change of its own. The command fails:

Booking carries the annotation 'CustomExclusion:Constraints' in the model the migration leads to. …
Remove the annotation and declare the object.

The annotation is in the snapshot, not in the model. migrations remove of the last 5.x migration fails the same way.

The planner took the second argument of a diff for "the model the migration leads to". EF Core's MigrationsScaffolder does not call it that way only: Down is GetDifferences(model, snapshot) whenever Up is not empty, and RemoveMigration asks HasDifferences(lastMigration.TargetModel, snapshot). So every rule written for the consumer's model also ran on a snapshot: the refusal of an earlier package's annotation, the derived-type refusal of #82, and the name claims of #96. The handover tests diff to no operations, and then EF Core never asks for Down.

Change

  • The consumer's model is the context's own design-time model, told by reference (SchemaOperationPlanner.IsOwn). Where a model stands in a diff says nothing. The three rules are asked of that one model on either side; every other model, a snapshot or a migration's target model, is only read.
  • An earlier package's annotation is read in every model but the context's own. A 5.x snapshot and the model that declares the same objects differ in nothing, whichever of the two the diff starts from.
  • In the context's own model, what 5.x declared is refused with a reader for it or without one (LegacyFormats.DeclaredIn). Without a reader it was passed over there: the model said an index exists that no migration makes.
  • What nothing reads is refused in a snapshot where a diff ends too, as it is where one starts (A 5.x annotation that no reader reads is passed over in silence #93).
  • The model is resolved when a declaration or an earlier package's annotation is met, not before: a context that declares nothing does not have it resolved by the planner.
  • The message says "in the context's own model". CLAUDE.md's rules for the planner say what the code does now, with the reason a test of such a rule has to diff both ways.

Tests

Locally: 517 kernel tests (4 of them on a live server), 178 of the PostgreSQL package with the live ones on PostgreSQL 16 and 18, 125 probes.

  • LegacyHandoverTests, on the snapshot the published 5.6.0 scaffolded: the first migration after the move with a new column is AddColumnOperation up and DropColumnOperation down; HasDifferences(snapshot, snapshot) is false.
  • LegacyDeclarationReaderTests: the old format in a snapshot is read where a diff ends: no operations against the model that declares the same, the object created again against one that dropped it, and two snapshots compared.
  • SchemaOperationPlannerTests: a snapshot with a declaration on a derived type of a shared table diffs to nothing against the base-type declaration, both ways.
  • NameClaimTests: a snapshot that holds a collision is read on either side; the context's own model is held to its names where a diff starts as well.
  • UnreadLegacyAnnotationTests: what 5.x declared in the context's own model is refused with a reader or without, also by HasDifferences; what nothing reads is refused where a diff ends.

They fail without the fix. The eight new tests and the extended one fail against main @ 948496a.

Guards shown to fail, seven defects seeded one at a time in a scratch copy, each failing at least one test: an earlier format with a reader refused in every model; what 5.x declared not refused in the own model; what nothing reads not required in a snapshot; the derived-type refusal on every model; name claims asked of whatever a diff ends with; name claims not asked of the own model where a diff starts; no model taken for the context's own (28 tests fail, which is every refusal for the consumer's model).

From a packed consumer outside the repository, with dotnet-ef 11.0.0-rc.3: migrations add refuses a constraint named like its table's primary key with SK1001, so the scaffolder hands the differ the same model instance; a second migration with a new column scaffolds Up and Down; a third is empty; migrations remove works twice.

Not run: the tool itself over a 5.x snapshot. The tests call the entry points the scaffolder calls; the run through dotnet ef belongs to the consumer smoke test (#34), where it is noted.

Decisions in this PR that are not confirmed

Not in this PR

#101's refusal of a TPC root, which is a rule for the consumer's model and builds on this.

🤖 Generated with Claude Code

…s in a diff

The planner took the second argument of a diff for the model the migration
leads to. EF Core's scaffolder asks for Down as GetDifferences(model, snapshot)
whenever Up is not empty, and migrations remove asks HasDifferences of two
snapshots. So the rules for the consumer's model ran on a snapshot: the first
migration after a move from 5.x could not be scaffolded when it held a change
of its own, and a 5.x migration could not be removed.

The consumer's model is now the context's own design-time model, by
reference. The refusal of an earlier package's annotation, the derived-type
refusal and the name claims are asked of that one model on either side of a
diff; every other model is only read.

In the context's own model, what 5.x declared is refused with a reader for it
or without one: without one it was passed over there.

Closes #98

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 11.0.0 milestone Nov 14, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working severity/high Wrong results, crash or failed writes in a realistic scenario package/core Affects CodoMetis.EFCore.SchemaKit (the kernel) package/postgresql Affects CodoMetis.EFCore.SchemaKit.PostgreSQL area/migrations The differ and generator decorators, snapshot format, EnsureCreated and the UseSchemaKit wiring labels Nov 14, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit d12d20f into main Nov 14, 2026
7 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/the-consumers-model-by-reference branch November 14, 2026 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/migrations The differ and generator decorators, snapshot format, EnsureCreated and the UseSchemaKit wiring bug Something isn't working package/core Affects CodoMetis.EFCore.SchemaKit (the kernel) package/postgresql Affects CodoMetis.EFCore.SchemaKit.PostgreSQL severity/high Wrong results, crash or failed writes in a realistic scenario

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The first migration after the move from 5.x cannot be scaffolded when it changes anything: EF Core diffs Down with the snapshot as the target

1 participant