Skip to content

feat!: the dialect says what a migration operation does - #199

Merged
CaffeinatedCoder merged 1 commit into
mainfrom
feat/198-effects-seam
Nov 25, 2026
Merged

CaffeinatedCoder merged 1 commit into
mainfrom
feat/198-effects-seam

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #198
Closes #105

The slice of #116 for preview.2 (decided 2026-11-25).

Problem

What a MigrationOperation does to the database is the provider's rule, and the kernel held copies of three providers' rules. A provider's package had no way to say what its generator does otherwise. One case had nowhere to be said at all: ToTable("role_grants", "grants") becomes ToTable("role_grants"), Npgsql 11.0.0 writes no statement for that move, and the planner took the table for moved. A constraint on it stayed in grants with the table, or a statement written after the move failed with 42P01 (#105).

Change

  • ISchemaDialect.EffectOf(MigrationOperation) answers with an OperationEffect, a closed union: Changes (the BaseChanges the operation stands for; none for one that touches nothing an object depends on), NotWritten (the tables it is about and the way out, as a sentence of the provider's package), Unknown. The planner asks it of every operation, in their order.
  • The kernel's SchemaDialect answers EF Core Relational's operations, and SQL Server's and SQLite's as before.
  • NpgsqlSchemaDialect says Npgsql's own: a change of a generated tsvector is a dropped column, its database operations touch nothing, and a table moved back to the default schema is not written. Each is held against Npgsql's generator in NpgsqlOperationEffectTests.
  • The planner refuses an operation that is not written when a declared object, on either side, is on one of its tables (A table moved back to the default schema stays where it was on Npgsql, and a statement written after the move fails with 42P01 #105). The way out for Npgsql is to name the schema, ToTable("x", "public"); Moving_the_table_back_with_the_default_schema_named applies that on PostgreSQL 16 and 18 and finds the table and its constraint where EnsureCreated() puts them. Taking the name off again afterwards is no move.
  • A context that declares nothing on the table is not touched.

Deviations from the proposal on #116:

  • The second provider's probe dialects do not override the seam. They have no rule to say that the kernel's dialect lacks, so an override would change nothing a test could see. The_dialect_says_what_an_operation_does and An_operation_of_another_package_is_taken_when_the_dialect_describes_it hold the seam in the kernel's tests with a dialect of their own.
  • NotWritten carries the way out. Only the provider's package knows it, and a refusal without it names no fix.
  • No service by which a third package describes its operation types. A dialect can describe them, as the test shows; a second way in waits for a package that needs it.

Tests

Offline: 772 (kernel), 209 (PostgreSQL package), 90 (second provider); the API probes: 127. Live: 4 and 77 on PostgreSQL 16 and on 18, 86 on SQL Server 2022. The consumer smoke test: 47 rows.

Nine rules were changed in turn, each run with the live tests on PostgreSQL 18, and a test failed for each:

Changed Fails
The planner asks the kernel's table, not the dialect both of the kernel's seam tests, the refusal's
An operation that is not written is passed over The_dialect_says_what_an_operation_does, the refusal's
It is refused whatever is on its table The_dialect_says_what_an_operation_does
An unknown operation is taken for harmless two of the kernel's
A move the dialect names does not carry names forward three of the PostgreSQL package's
Npgsql: a changed tsvector is an alteration two rows of The_dialect_says_a_dropped_column_where_the_generator_drops_one (the first form of this change was no change, and was redone)
Npgsql: the move back is a move two
Npgsql: leaving the default schema's name is not written either three, the live test among them
Npgsql: its database operations are unknown Every_operation_type_of_Npgsql_is_described

breaking: ISchemaDialect has a new member, in the contract (SK9001), and a migration that applied and left the table behind is refused.

🤖 Generated with Claude Code

ISchemaDialect.EffectOf answers an operation with an OperationEffect: the
BaseChanges it stands for, that the provider writes nothing for it, or
that nobody knows it. The planner asks it of every operation. The
kernel's SchemaDialect answers EF Core Relational's operations, and SQL
Server's and SQLite's until each has a dialect of its own.

NpgsqlSchemaDialect says Npgsql's rules, each held against its generator:
a change of a generated tsvector is a dropped column, its database
operations touch nothing, and a table moved back to the default schema
is not written.

An operation that is not written is refused when a declared object is on
one of its tables: the table would stay where it was, and the object
with it or a statement after it would fail. For Npgsql the way out is to
name the schema, ToTable("x", "public"), which it writes.

Closes #198
Closes #105

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 11.0.0 milestone Nov 25, 2026
@CaffeinatedCoder CaffeinatedCoder added enhancement New feature or request breaking Changes an answer or a signature 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 25, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit fac25ed into main Nov 25, 2026
10 of 11 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the feat/198-effects-seam branch November 25, 2026 16:31
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 breaking Changes an answer or a signature enhancement New feature or request package/core Affects CodoMetis.EFCore.SchemaKit (the kernel) package/postgresql Affects CodoMetis.EFCore.SchemaKit.PostgreSQL

Projects

None yet

1 participant