Repository navigation
fix: an operation only a 5.x generator rendered is refused, not replayed as another object - #128
Merged
Merged
Conversation
…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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #110
Problem
Up to 5.0.1,
EFCore.ComplexIndexesscaffolded a temporal constraint asAddUniqueConstraint(…)carrying the annotationCustomTemporal: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: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,
SchemaKitSqlGeneratorrefuses 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.csbeside the model-side one (#93), with its source in the remarks. It was established from 5.x's source over every tag (1.0.0tov5.6.0), not from the issue's guess, which lackedCustomIndex:IndexParts:CustomTemporal:WithoutOverlaps(the period column)AddUniqueConstraintOperationNpgsqlComplexIndexSqlGenerator:ADD CONSTRAINT … UNIQUE (…, "period" WITHOUT OVERLAPS), the period lastUNIQUE (…)under the same name. Applies. SilentCustomTemporal:ForeignKeyDependentPeriodandCustomTemporal:ForeignKeyPrincipalPeriodAddForeignKeyOperationFOREIGN KEY (…, PERIOD "a") REFERENCES t (…, PERIOD "b"); anything butNO ACTIONthrownCustomIndex:IndexParts(the parts as JSON)CreateIndexOperationNULLS FIRST/LASTCREATE INDEXfrom the parts, with method, operator classes, collations,INCLUDE,NULLS NOT DISTINCT, storage parameters, filter__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 hereCustomIndex:AfterTableRebuild(true)CreateIndexOperationSqliteRebuildMigrationsSqlGenerator: 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__requires_UseComplexIndexes__()in its filter, which fails at apply5.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.CLAUDE.md, "The host": one bullet added.Tests
Kernel,
LegacyOperationAnnotationTests, every row on Npgsql, SQL Server and SQLite:issues/28in the message; each of the foreign key's two alone as well;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.ApiProbes125 passed.Shown to fail, in a scratch copy (rsync without
.git,bin,obj), both suites run for each: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_refusedAn_operation_whose_annotation_a_rewriter_took_is_generated(18),An_annotation_a_rewriter_left_is_still_refused(3, it names the other annotation)CustomTemporal:WithoutOverlapsoff the list…is_refused ("unique")(3),The_table_is_named_with_its_schema(3); PostgreSQL 1, as aboveCustomTemporal:ForeignKeyDependentPeriodoff…is_refused ("foreign key")and("dependent alone")CustomTemporal:ForeignKeyPrincipalPeriodoff…is_refused ("principal alone"),An_annotation_a_rewriter_left_is_still_refusedCustomIndex:IndexPartsoff…is_refused ("expression index"),An_annotation_in_a_shape_5x_never_wrote_is_refused_tooCustomIndex:AfterTableRebuildoff…is_refused ("after rebuild"),An_annotation_in_a_shape_5x_never_wrote_is_refused_tooDecisions in this PR that are not confirmed
CustomIndex:IndexPartsis 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.WithoutOverlapsonly as a string on anAddUniqueConstraintOperation,AfterTableRebuildonly astrue. 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".CreateTableOperationis not looked at: 5.x never stamped one and its generator did not render one there.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.Initial.csas text and generates the operations they hold on all three providers; the compiled replay is in the PostgreSQL package's suite.🤖 Generated with Claude Code