Skip to content

fix: an operation only a 5.x generator rendered is refused, not replayed as another object - #128

Merged
CaffeinatedCoder merged 1 commit into
mainfrom
fix/legacy-operation-annotations
Nov 14, 2026
Merged

CaffeinatedCoder merged 1 commit into
mainfrom
fix/legacy-operation-annotations

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #110

Problem

Up to 5.0.1, EFCore.ComplexIndexes scaffolded a temporal constraint as AddUniqueConstraint(…) carrying the annotation CustomTemporal:WithoutOverlaps, and its own SQL generator rendered the constraint from it. SchemaKit has no rewriter for it (#28), so the operation reached the provider's generator as it was:

ALTER TABLE "Tariff" ADD CONSTRAINT "AK_Tariff_ProductId_Valid" UNIQUE ("ProductId", "Valid");

A plain unique constraint under the temporal one's name. A fresh database built from such a history accepts overlapping periods, and nothing says so.

Change

After the rewriters, SchemaKitSqlGenerator refuses an operation that still carries an annotation only a 5.x generator rendered. The message names the operation, its table and the annotation, says what 5.x wrote for it, that this version cannot replay it, and links #28.

The list is in LegacyFormats.cs beside the model-side one (#93), with its source in the remarks. It was established from 5.x's source over every tag (1.0.0 to v5.6.0), not from the issue's guess, which lacked CustomIndex:IndexParts:

Annotation On Published in What 5.x's generator rendered What the provider's generator writes
CustomTemporal:WithoutOverlaps (the period column) AddUniqueConstraintOperation to 5.0.1; SQL at design time from 5.0.2 NpgsqlComplexIndexSqlGenerator: ADD CONSTRAINT … UNIQUE (…, "period" WITHOUT OVERLAPS), the period last a plain UNIQUE (…) under the same name. Applies. Silent
CustomTemporal:ForeignKeyDependentPeriod and CustomTemporal:ForeignKeyPrincipalPeriod AddForeignKeyOperation 5.0.1 the same generator, only with both: FOREIGN KEY (…, PERIOD "a") REFERENCES t (…, PERIOD "b"); anything but NO ACTION thrown a plain foreign key. Whether it applies depends on what the principal's constraint was replayed as
CustomIndex:IndexParts (the parts as JSON) CreateIndexOperation every version to 5.6.0, for an index with an expression or NULLS FIRST/LAST the same generator: the whole CREATE INDEX from the parts, with method, operator classes, collations, INCLUDE, NULLS NOT DISTINCT, storage parameters, filter the operation's columns: the parts' text as identifiers and a last column __requires_UseNpgsqlComplexIndexes__. Fails at apply on PostgreSQL and SQL Server. On SQLite with double-quoted string literals on (SQLite's own default build) it creates an index over a constant, by 5.x's own remark; not measured here
CustomIndex:AfterTableRebuild (true) CreateIndexOperation from 5.5.0, SQLite SqliteRebuildMigrationsSqlGenerator: taken out of the list, the marker removed from its filter, created after the table rebuild under the table's name after the migration's renames the create where it stands, with __requires_UseComplexIndexes__() in its filter, which fails at apply

5.x had no SQL generator for SQL Server. The provider annotations it forwarded to an index (Npgsql:…, SqlServer:…) are the provider's own and its generator reads them. Everything else of 5.x is stored in models, which is #93's.

How the guard is built:

  • LegacyFormats.RequireRewritten(operations) reads the operations alone. It needs no model and no service, so the rule of the host (nothing the generator is built from may need the model) is untouched, and it is the same on Npgsql, SQL Server and SQLite.
  • It runs after the rewriters. A rewriter leaves the guard by taking the annotation off the operation or replacing the operation, as a reader leaves A 5.x annotation that no reader reads is passed over in silence #93's by being registered.
  • It holds an annotation whatever its value and whatever operation carries it.
  • CLAUDE.md, "The host": one bullet added.

Tests

Kernel, LegacyOperationAnnotationTests, every row on Npgsql, SQL Server and SQLite:

  • each annotation on its operation is refused, with the operation, table, annotation and issues/28 in the message; each of the foreign key's two alone as well;
  • the premise: the provider's own generator answers the stamped operation exactly as the bare one, and on PostgreSQL that is the issue's statement verbatim;
  • the same operation without the annotation is generated as the inner generator generates it;
  • an operation whose annotation a test rewriter took is generated; one of which a rewriter took only one of two is still refused;
  • neither fixture migration of 5.6.0 holds one of the names, and the operations it holds for the same objects generate.

PostgreSQL package, LegacyReplayTests: both fixture migrations (Scaffolded, ScaffoldedOtherKinds), Up and Down, compiled as checked in, go through the context's real generator; the second with its temporal statement put back as 5.0.1 scaffolded it is refused.

dotnet build CodoMetis.EFCore.SchemaKit.slnx: no warning. Kernel 604 passed; PostgreSQL package 195 passed on PostgreSQL 18 and on 16, live; SchemaKit.ApiProbes 125 passed.

Shown to fail, in a scratch copy (rsync without .git, bin, obj), both suites run for each:

Broken Tests that fail
the list emptied kernel 27: An_operation_only_5x_rendered_is_refused (18), The_table_is_named_with_its_schema (3), An_annotation_in_a_shape_5x_never_wrote_is_refused_too (3), An_annotation_a_rewriter_left_is_still_refused (3); PostgreSQL 1: The_same_migration_with_the_temporal_constraint_as_5_0_1_scaffolded_it_is_refused
the call removed from the generator the same 27 and 1
the check moved before the rewriters kernel 21: An_operation_whose_annotation_a_rewriter_took_is_generated (18), An_annotation_a_rewriter_left_is_still_refused (3, it names the other annotation)
CustomTemporal:WithoutOverlaps off the list kernel 6: …is_refused ("unique") (3), The_table_is_named_with_its_schema (3); PostgreSQL 1, as above
CustomTemporal:ForeignKeyDependentPeriod off kernel 6: …is_refused ("foreign key") and ("dependent alone")
CustomTemporal:ForeignKeyPrincipalPeriod off kernel 6: …is_refused ("principal alone"), An_annotation_a_rewriter_left_is_still_refused
CustomIndex:IndexParts off kernel 6: …is_refused ("expression index"), An_annotation_in_a_shape_5x_never_wrote_is_refused_too
CustomIndex:AfterTableRebuild off kernel 6: …is_refused ("after rebuild"), An_annotation_in_a_shape_5x_never_wrote_is_refused_too

Decisions in this PR that are not confirmed

  1. CustomIndex:IndexParts is on the list, which the issue did not name. It is the annotation 5.x used most and still scaffolds in 5.6.0. Consequence: a history with an expression index of 5.x is refused at generation by every provider, where before it failed at apply on PostgreSQL on the sentinel column. That is a clearer failure, not a new one, except for SQLite's silent case.
  2. Any value, any operation. 5.x read WithoutOverlaps only as a string on an AddUniqueConstraintOperation, AfterTableRebuild only as true. The guard refuses the name wherever it is, following Legacy replay: migrations scaffolded by 5.x apply to a fresh database #28's "an owned annotation in an unknown shape is an error".
  3. Top-level operations only. A unique constraint or foreign key nested in a CreateTableOperation is not looked at: 5.x never stamped one and its generator did not render one there.
  4. The message offers two ways out: apply the migration with 5.x, or replace the operation in the migration with migrationBuilder.Sql(…) of the statement 5.x wrote. The second is editing an applied migration by hand; say so if the message should not suggest it.
  5. The fixture is not compiled in the kernel's suite. It names Npgsql types and the context of the PostgreSQL tests' assembly, so the kernel's test reads the two Initial.cs as text and generates the operations they hold on all three providers; the compiled replay is in the PostgreSQL package's suite.
  6. No changelog line, as in the earlier fixes of this round: nothing is published.

🤖 Generated with Claude Code

…yed as another object

Up to 5.0.1 EFCore.ComplexIndexes scaffolded a temporal constraint as
AddUniqueConstraint(…) carrying CustomTemporal:WithoutOverlaps, and its own
SQL generator rendered the constraint from the annotation. SchemaKit has no
rewriter for it, so the operation reached the provider's generator as it was
and became a plain unique constraint under the temporal one's name: a fresh
database built from such a history accepted overlapping periods, and nothing
said so.

After the rewriters, SchemaKitSqlGenerator now refuses an operation that
still carries an annotation only a 5.x generator rendered, naming the
operation, its table, the annotation and #28. The list is taken from 5.x's
two generators and the differs that stamped for them, over every published
version: CustomTemporal:WithoutOverlaps, the temporal foreign key's
ForeignKeyDependentPeriod and ForeignKeyPrincipalPeriod, and on a CreateIndex
CustomIndex:IndexParts and CustomIndex:AfterTableRebuild. A rewriter leaves
the guard by taking the annotation off the operation. The check reads the
operations alone, so it is the same on Npgsql, SQL Server and SQLite and
needs no model.

Closes #110

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 silent Answers wrongly without throwing; the fix ships as a minor, never a patch package/core Affects CodoMetis.EFCore.SchemaKit (the kernel) package/postgresql Affects CodoMetis.EFCore.SchemaKit.PostgreSQL severity/medium Inconsistency or failure in a narrow scenario area/migrations The differ and generator decorators, snapshot format, EnsureCreated and the UseSchemaKit wiring labels Nov 14, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit a49ea3a into main Nov 14, 2026
7 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/legacy-operation-annotations branch November 14, 2026 09:54
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/medium Inconsistency or failure in a narrow scenario silent Answers wrongly without throwing; the fix ships as a minor, never a patch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

An operation scaffolded by an early 5.x with CustomTemporal:WithoutOverlaps replays as a plain unique constraint

1 participant