Repository navigation
Description
Found by the analysis of #77 and #79, reproduced on PostgreSQL 16.15 and 18.6. Nothing is released.
What happens
Npgsql's generator writes DROP COLUMN and ADD COLUMN for an AlterColumnOperation whose ComputedColumnSql or IsStored differs from the old column's. The kernel maps every AlterColumnOperation to BaseChange.ColumnAltered, and the exclusion contributor answers Unaffected. PostgreSQL drops an exclusion constraint with a column that is one of its elements, without saying so.
Reproduction
Source: the scheduling model (GranteeId, RoleId, Period, a condition on RevokedOn, named). Target: the same, with GranteeId as HasComputedColumnSql("\"RoleId\" * 10", stored: true).
- The diff is one
AlterColumnOperationand nothing of SchemaKit's. - It applies.
pg_constraintthen holds no exclusion constraint. EnsureCreated()of the target model has the constraint.- The target model against itself diffs to nothing, so no later migration puts it back.
The other direction (computed to plain) is the same. With the column in the condition only, the apply fails with 2BP01, which is loud.
Fix
BaseChanges has to say what the provider's statement does: where Npgsql drops and adds the column, the change is a ColumnDropped (or a case of its own), so that Lost and RebuildAround apply as for a drop. The plan's section 3.7 lists a computed column as not measured; 5.x had this as its issue 184. Check SQL Server's generator for the same.
Tests
Live: scheduling to the computed model leaves the catalog EnsureCreated() builds. Offline: the add stands after the column's operation. A test that holds the list of what makes Npgsql drop and add, against its generator, as RebuiltOnSqlite is held.
Activity