Skip to content

feat: a name the model takes twice is refused at the diff, every collision at once - #97

Merged
CaffeinatedCoder merged 1 commit into
mainfrom
feat/name-claims
Nov 12, 2026
Merged

CaffeinatedCoder merged 1 commit into
mainfrom
feat/name-claims

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #96

Problem

A contributor answers Claims for each descriptor, and nothing asked. Two objects that take one name were found by the database at apply, in the middle of a migration: an exclusion constraint named like an index anywhere in its schema, like its table's primary key, or like another unnamed constraint over the same elements, which gets the same default name.

Change

  • The planner collects the names the target model takes (NameClaims): each declared object's claims from its contributor, and those of EF Core's own tables, indexes, keys, foreign keys, check constraints and sequences from the dialect.
  • ISchemaDialect.Claims(SchemaModelObject, TableRef, Identifier) is the provider's rule for EF Core's objects. The kernel's default: a table and a sequence within their schema, an index within its table, a constraint within its table. PostgreSQL's: an index is a relation of the schema; a primary key and a unique constraint take a constraint name and a relation name.
  • Two equal claims are a collision when at least one party is SchemaKit's. Names compare ordinally unless either declaration's NameComparison says otherwise. Two objects that collide in two namespaces are one finding.
  • Every collision arrives at once, in one SchemaValidationException whose Diagnostics are SchemaDiagnostic.NameCollision, id SK1001, with both parties and the namespace named. Both types are public and unmarked: a consumer catches and reads them. The exception derives from InvalidOperationException, like every other refusal.
  • Target only. A snapshot that holds a collision still diffs.

Tests

Locally: 508 kernel tests, 126 PostgreSQL tests offline, 50 on a live server, on PostgreSQL 16.15 and 18.6.

  • Offline, one model per namespace rule: like the table's primary key, a foreign key or a check constraint of the same table (refused); like an index, a unique constraint or an exclusion constraint of another table, a table, a sequence (refused, for the index behind it); like a check constraint of another table, the same name in two schemas, another case (taken).
  • The server's word for each row (NameClaimLiveTests): the same names added by hand to a database are refused with 42P07 or 42710, or taken, exactly where the check refuses or lets through.
  • Two findings in one exception; a collision in the snapshot alone; a new database and HasDifferences refused alike; two of EF Core's own objects not reported.
  • The kernel's defaults and the comparison rule on Npgsql, SQL Server and SQLite with the sample contributors.

Guards shown to fail. 26 defects seeded one at a time, each failing its test: the planner not asking, the source held to it, each kind of EF Core's objects left out, each comparison loosened, each row of both dialects' tables changed, either of the exclusion constraint's two claims removed, and the seed #84 left open (the constraint's name carrying its table's schema). One survived the first run and was right to: I had added the model's default schema to a table without one, and EF Core's relational model does that already. The code is removed.

Decisions in this PR that are not confirmed

  • All findings at once (the draft's Q7, which Validation and diagnostics: name claims across kinds, every finding at once #44 asks to confirm).
  • SchemaDiagnostic holds text only (Name, Namespace, First, Second), not the DeclarationRef the design sketches. It keeps the unmarked type free of the marked contract.
  • SK1001 is now a permanent id.
  • The dialect answers per kind of object, through a new enum SchemaModelObject, and not by walking the model itself.
  • The kernel's default scopes are a guess for a provider without a package. On SQL Server a constraint is an object of the schema, so a collision between a constraint and a table there is missed until its package (SqlServerIndex: clustered and nonclustered, typed #29) says so.
  • Views and other providers' objects are not entered.

Not in this PR

Staying with #44: ids for the kernel's existing refusals, warnings through the diagnostics logger.

🤖 Generated with Claude Code

…ision at once

The planner collects the names the target model's objects take: each
declared object's claims from its contributor, EF Core's own tables, indexes,
keys, foreign keys, check constraints and sequences from the dialect. Two
equal claims with at least one party of SchemaKit's are a
SchemaDiagnostic.NameCollision (SK1001), and all of them arrive in one
SchemaValidationException.

PostgreSQL's table of namespaces is held against the server on 16 and 18.

Closes #96

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 11.0.0 milestone Nov 12, 2026
@CaffeinatedCoder CaffeinatedCoder added enhancement New feature or request 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 12, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit 948496a into main Nov 12, 2026
7 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the feat/name-claims branch November 12, 2026 17:38
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 enhancement New feature or request package/core Affects CodoMetis.EFCore.SchemaKit (the kernel) package/postgresql Affects CodoMetis.EFCore.SchemaKit.PostgreSQL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Name claims: a name taken twice is reported at the diff, every collision at once

1 participant