Skip to content

fix: an alter the provider writes as drop and add is a dropped column, and an extension an object comes to need is ensured - #87

Merged
CaffeinatedCoder merged 1 commit into
mainfrom
fix/altered-column-dropped-and-added
Nov 12, 2026
Merged

CaffeinatedCoder merged 1 commit into
mainfrom
fix/altered-column-dropped-and-added

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #80
Closes #81

Both come from one assumption: that an AlterColumnOperation leaves what reads the column alone.

Problem

#80, silent. Npgsql and SQL Server write DROP COLUMN and ADD COLUMN for an alter whose ComputedColumnSql or IsStored changed. The kernel said ColumnAltered, the exclusion contributor answered Unaffected, and PostgreSQL dropped the constraint with its element column without a word. The migration applied, the constraint was gone, and the model against its snapshot diffed to nothing, so no later migration put it back.

#81, loud. A column type change that begins the need for btree_gist (ltree to text) created nothing, so no extension was ensured, while PostgreSQL rebuilt the constraint's index under the new type: 42704: data type text has no default operator class for access method "gist". A test of mine pinned that migration as right.

Change

  • BaseChanges.DroppedAndAdded: an alter the provider writes as drop and add becomes ColumnDropped. The rule is the two generators' own condition, plus Npgsql's generated tsvector, whose computation it derives from two annotations. Contributors then answer as for a drop: Lost for an element column (the constraint is added again after), RebuildAround for a column only the condition reads (2BP01 otherwise).
  • The planner's extension step also takes what a target object depends on and its source did not, for objects that stay. Not every extension of every object that stays: a rename under a constraint must not write CREATE EXTENSION.
  • design/schemakit-core-plan.md, section 3.7: a computed column is no longer "not measured".

Decisions to confirm

  1. ColumnDropped, not a new case of BaseChange. To what reads the column the two are the same event, and the union stays as it is.
  2. The rule is one for all providers, not one per provider: Npgsql's and SQL Server's conditions are the same, and SQLite rebuilds the table for any alter anyway.

Found on the way

  • Npgsql's generator rewrites the operation it is handed: it turns the tsvector annotations into a computation and removes one. A test that asked the kernel's rule after generating read the generator's answer back. That is how the one surviving mutation was found.
  • text to ltree does not apply at all, with or without a constraint: PostgreSQL casts no text to ltree by itself (42804). Npgsql's statement, not SchemaKit's.

Tests

451 kernel, 64 PostgreSQL offline, 28 live on PostgreSQL 16.15 and 18.6, 125 probes.

Each guard shown to fail, in a scratch copy:

Mutation Fails
Every alter is an alteration 2 PostgreSQL offline, 2 kernel, 3 live
The stored flag not looked at the generator test, SQL Server "persisted"
The tsvector annotations not looked at the generator test, 2 Npgsql rows (survived until the test asked first)
Every alter is a drop 13 generator rows, 4 others
Extensions for what is created only A_type_change_…_brings_the_extension_it_begins_to_need, the kernel's, live A_type_change_that_begins_the_need_for_the_extension_applies
Extensions of every object that stays 8 PostgreSQL offline, 2 kernel

🤖 Generated with Claude Code

…, and an extension an object comes to need is ensured

Closes #80. Closes #81.

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 bug Something isn't working silent Answers wrongly without throwing; the fix ships as a minor, never a patch severity/high Wrong results, crash or failed writes in a realistic scenario package/core Affects CodoMetis.EFCore.SchemaKit (the kernel) package/postgresql Affects CodoMetis.EFCore.SchemaKit.PostgreSQL area/constraints Exclusion constraints, row guards and other constraint-like objects area/migrations The differ and generator decorators, snapshot format, EnsureCreated and the UseSchemaKit wiring labels Nov 12, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit 31f6855 into main Nov 12, 2026
6 of 7 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/altered-column-dropped-and-added branch November 12, 2026 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/constraints Exclusion constraints, row guards and other constraint-like objects 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/high Wrong results, crash or failed writes in a realistic scenario silent Answers wrongly without throwing; the fix ships as a minor, never a patch

Projects

None yet

1 participant