Skip to content

fix: a table without a schema is compared in the schema the database puts it in - #133

Merged
CaffeinatedCoder merged 1 commit into
mainfrom
fix/null-schema-claims
Nov 14, 2026
Merged

CaffeinatedCoder merged 1 commit into
mainfrom
fix/null-schema-claims

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #100

Problem

In a model without a default schema, a table without a schema claimed its names in schema null, and a table mapped with ToTable("x", "public") in schema public. NameClaims compared the two as text, so an exclusion constraint on role_grants and an EF Core index of the same name on public.bookings raised no SK1001, and the migration failed at apply with 42P07: on a stock PostgreSQL database both tables are in public.

Change

  • ISchemaDialect.DefaultSchema (new, under the experimental contract): the schema the database puts an object in when its statement names none, or null when the dialect does not know it. The docs say what a search_path that points elsewhere means: a database the model does not describe.
  • SchemaDialect.DefaultSchema is null. The kernel does not guess for a provider without a package (dbo on SQL Server comes with SqlServerIndex: clustered and nonclustered, typed #29; SQLite has one namespace per database). With null, a table without a schema shares a namespace only with another table without one, as before.
  • NpgsqlSchemaDialect.DefaultSchema is public.
  • NameClaims.Same compares schemas under the dialect's default. A model's own HasDefaultSchema still arrives through the relational model, as before.
  • CLAUDE.md: one line under "The planner", one under "The PostgreSQL package".

Tests

  • PostgreSQL package, NameClaimTests:
    • A_table_without_a_schema_is_in_public_when_the_model_sets_none: the scenario from the issue is refused with SK1001.
    • A_table_without_a_schema_is_not_in_another_named_one: the reverse case. The table without a schema against one in ops collides with nothing.
    • The_dialect_puts_a_table_without_a_schema_in_public.
  • Their rows on the server, Integration/NameClaimLiveTests:
    • The_server_refuses_a_name_taken_in_public_for_a_table_created_without_a_schema: 42P07.
    • The_server_takes_a_name_taken_in_another_schema_for_a_table_created_without_one.
  • Kernel, Migrations/NameClaimTests:
    • Without_a_providers_rule_a_table_without_a_schema_is_in_no_named_one on Npgsql and SQL Server. SQLite has no schemas to put a table in.
    • The_kernels_dialect_knows_no_default_schema on all three providers.

I broke each rule in a scratch copy (rsync without .git, bin, obj) and ran the suites:

  • With NameClaims comparing schemas as text again, A_table_without_a_schema_is_in_public_when_the_model_sets_none fails.
  • With NpgsqlSchemaDialect.DefaultSchema null, A_table_without_a_schema_is_in_public_when_the_model_sets_none and The_dialect_puts_a_table_without_a_schema_in_public fail.
  • With the kernel's dialect guessing public, Without_a_providers_rule_a_table_without_a_schema_is_in_no_named_one fails (Npgsql and SqlServer), and so does The_kernels_dialect_knows_no_default_schema (all three providers).

Every suite passes:

  • kernel: 627 tests, on PostgreSQL 18 and 16
  • PostgreSQL package: 203 tests, on PostgreSQL 18 and 16
  • SchemaKit.ApiProbes: 125 tests

dotnet build CodoMetis.EFCore.SchemaKit.slnx has no warning.

Decisions in this PR that are not confirmed

  • A new member on ISchemaDialect. The interface is under SK9001 until rc.1, so adding to it is allowed. A dialect outside the repository that implements the interface directly instead of deriving from SchemaDialect will no longer compile.
  • What public stands for. It is the stock server's answer, not the answer of the session that applies the migration. The planner does not read search_path at diff time, since a diff has no connection.
  • How schema names compare. A schema is compared with the same comparison as the names, ordinal unless a declaration's NameComparison says otherwise.
  • No CHANGELOG line. A parallel session owns CHANGELOG.md for the preview.

🤖 Generated with Claude Code

…puts it in

NameClaims compared a table without a schema and one in public as two
schemas, so no SK1001 was raised and the migration failed at apply with
42P07. The dialect now names the schema the database puts an unqualified
table in (ISchemaDialect.DefaultSchema): public for PostgreSQL, null for
the kernel's own dialect, which does not guess.

Closes #100

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 11.0.0 milestone Nov 14, 2026
@CaffeinatedCoder CaffeinatedCoder added 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 area/migrations The differ and generator decorators, snapshot format, EnsureCreated and the UseSchemaKit wiring labels Nov 14, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit 43bc9e9 into main Nov 14, 2026
8 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/null-schema-claims branch November 14, 2026 15:10
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Name claims take a table without a schema and a table in public for two schemas, and the collision fails at apply

1 participant