Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions docs/binary-coercible-type-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,11 @@ relabels only a column that no partitioned index reads, as a key, in an expressi
predicate, whether the index stands alone or backs a constraint. It reads those indexes off
the live parent, takes the rewrite route for a column one of them reads, and takes it marked
unverified when they were not read. The change is refused with `copy-and-swap-refused` and
nothing executed: cause `copy-and-swap-not-enabled` while the run has not opened the
copy-and-swap route, the default, and `copy-and-swap-partitioned` once it has, since that
route refuses a partitioned parent. A foreign key on the column does not change the decision: it is
nothing executed: cause `partitioned-index-rebuild` while the run has not opened the
copy-and-swap route, the default, whose detail names the path that runs the change (drop the
index in a run of its own, then retype the column and recreate the index), and
`copy-and-swap-partitioned` once it has, since that route refuses a partitioned parent. A
parent whose partitioned indexes were not read keeps `copy-and-swap-not-enabled`. A foreign key on the column does not change the decision: it is
re-created without a scan, on a parent as on a plain table.

The `timestamp ↔ timestamptz` rule reads two facts off the live database: the session
Expand Down
2 changes: 1 addition & 1 deletion docs/capabilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ or the only online form is a direct statement the operator runs).
| `ALTER COLUMN ... SET EXPRESSION` (changed stored generated expression) | 🟡 | copy-and-swap | Yes | Planned but not executed. `diff` shows a changed stored generated expression as one `SET EXPRESSION` statement of kind `set-generated-expression`, refused with `unsupported-statement`, rather than a drop and re-add that would also drop the column's indexes. It recomputes every row under `ACCESS EXCLUSIVE`, and the statement needs PostgreSQL 17 or later. An expression whose text the file keeps is not a change, even when the file retypes a column it reads: see the retyping row in [limitations.md](limitations.md#current-limitations) |
| `ADD COLUMN` with inline `UNIQUE`/`PRIMARY KEY`/`REFERENCES`/`CHECK` | 🟡 | native, planned flow | Yes | The inline constraint does its index build or validation scan under the `ADD COLUMN`'s `ACCESS EXCLUSIVE` lock; refused with guidance to add the column first, then build the constraint online |
| `DROP COLUMN` | ✅ | native, as-is | Yes | Metadata-only; flagged **destructive** in the plan report. `migrate` refuses it with `destructive-change` unless `--allow-destructive` names the table (`migrate --desired` refuses a destructive plan whole unless `--expect-fingerprint` pins the reviewed plan and `--allow-destructive` names the table); dropping a column and adding it back in one statement is refused with the `alter-column-type-in-place` guidance. Refused with `replica-identity` when a replica identity index the drop reaches keys on the column: the table's own, or one on a partition or inheritance child below it unless the statement says `ONLY`. Refused with `dependent-view`, naming the views, when a view or materialized view reads the column, on a table the drop reaches. Refused with `dependent-policy`, naming the policies, when a row-level security policy reads the column, on a table the drop reaches or on another table through a subquery. Refused with `dependent-trigger`, `dependent-rule`, `dependent-publication`, `dependent-generated-column`, or `partition-key`, naming the objects, when a trigger's `UPDATE OF` list or `WHEN` condition names the column, a rewrite rule reads it, a publication's column list or row filter names it, a generated column reads it, or it is in a partition key, on a table the drop reaches. Refused with `cascading-drop` when the statement says `CASCADE`, which would also drop the views and policies that read the column. A trigger whose PL/pgSQL function reads the column, which PostgreSQL records no dependency for and lets the drop break, is named in the decision's `trigger_reads` with the line that reads it, and a trigger whose function cannot be checked in `unchecked_triggers`; neither changes the route. A `migrate --desired` drop reads the object again under the table's lock and refuses with `dropped-object-drift`, dropping nothing, if its definition is not the one the reviewed plan carried. On a partitioned table it drops the column from the parent and every partition, sub-partitions included, after locking the whole tree: it refuses with `dropped-column-partition-key` when the column is in the partition key of the parent or of a sub-partitioned partition, and with `dropped-column-partition-dependent`, naming each object, when a partition carries an index, CHECK or foreign key, statistics object, sequence, or other object of its own on the column, which the parent's plan did not review; copies of the parent's indexes and constraints go with the parent's. On a table with inheritance children it refuses with `dropped-object-has-descendants`. `migrate --alter` makes no such partition check beyond the planner's `partition-key` refusal: the statement the operator wrote drops a partition's own objects on the column, as it drops the table's own. |
| `ALTER COLUMN TYPE`, binary-coercible (proven against live column facts) | ✅ | native, as-is | Yes | Catalog relabel, e.g. `varchar(50)` → `varchar(100)`, `varchar` → `text`, `timestamp(3)` → `timestamp(6)`, `varbit(8)` → `varbit(16)`, `cidr` → `inet`, and `timestamp` → `timestamptz` in a UTC session for a column no index or foreign key reads, refused with `time-zone-drift` when the session that runs it is no longer in UTC. On a partitioned parent a relabel is planned only for a column no partitioned index reads: PostgreSQL rebuilds every partition's index attached to one that reads it under `ACCESS EXCLUSIVE` on the whole tree, so that change takes the rewrite route, which refuses it with `copy-and-swap-refused`, nothing executed: cause `copy-and-swap-not-enabled` while the run has not opened the route (the default), and `copy-and-swap-partitioned` once it has. Refused with `dependent-view`, naming the views, when a view or materialized view reads the column, and with `dependent-policy`, naming the policies, when a row-level security policy reads it; refused likewise with `dependent-trigger`, `dependent-rule`, `dependent-publication`, `dependent-generated-column`, or `partition-key` when a trigger's `UPDATE OF` list or `WHEN` condition names it, a rewrite rule reads it, a publication's column list or row filter names it, a generated column reads it, or it is in a partition key; see [binary-coercible-type-changes.md](binary-coercible-type-changes.md#no-rewrite-is-not-no-cost) A trigger whose PL/pgSQL function reads the column, which PostgreSQL records no dependency for, is named in the decision's `trigger_reads` with the line that reads it, and a trigger whose function cannot be checked in `unchecked_triggers`; neither changes the route. |
| `ALTER COLUMN TYPE`, binary-coercible (proven against live column facts) | ✅ | native, as-is | Yes | Catalog relabel, e.g. `varchar(50)` → `varchar(100)`, `varchar` → `text`, `timestamp(3)` → `timestamp(6)`, `varbit(8)` → `varbit(16)`, `cidr` → `inet`, and `timestamp` → `timestamptz` in a UTC session for a column no index or foreign key reads, refused with `time-zone-drift` when the session that runs it is no longer in UTC. On a partitioned parent a relabel is planned only for a column no partitioned index reads: PostgreSQL rebuilds every partition's index attached to one that reads it under `ACCESS EXCLUSIVE` on the whole tree, so that change takes the rewrite route, which refuses it with `copy-and-swap-refused`, nothing executed: cause `partitioned-index-rebuild` while the run has not opened the route (the default), whose detail names the path that runs it (drop the index in a run of its own, then retype the column and recreate the index), and `copy-and-swap-partitioned` once it has. Refused with `dependent-view`, naming the views, when a view or materialized view reads the column, and with `dependent-policy`, naming the policies, when a row-level security policy reads it; refused likewise with `dependent-trigger`, `dependent-rule`, `dependent-publication`, `dependent-generated-column`, or `partition-key` when a trigger's `UPDATE OF` list or `WHEN` condition names it, a rewrite rule reads it, a publication's column list or row filter names it, a generated column reads it, or it is in a partition key; see [binary-coercible-type-changes.md](binary-coercible-type-changes.md#no-rewrite-is-not-no-cost) A trigger whose PL/pgSQL function reads the column, which PostgreSQL records no dependency for, is named in the decision's `trigger_reads` with the line that reads it, and a trigger whose function cannot be checked in `unchecked_triggers`; neither changes the route. |
| `ALTER COLUMN TYPE`, general (or with `USING`) | ✅ preview | copy-and-swap | Yes | Table rewrite; runs through copy-and-swap: the changed shape is built as a shadow table, filled in chunks (a `USING` expression is applied per row), verified, and swapped in under the source's name. The route is in preview and runs only when the run opens it with `--copy-and-swap` (`CopySwapOptions.Enabled`); without it the statement is refused with `copy-and-swap-refused`, cause `copy-and-swap-not-enabled`, before the route's preflight runs or anything is written, and `migrate --dry-run` and `migrate --desired --dry-run`, which take `--copy-and-swap` as the run does, end in that same refusal without it. Refused with `dependent-view`, naming the views, when a view or materialized view reads the column, and with `dependent-policy`, naming the policies, when a row-level security policy reads it, and likewise with `dependent-trigger`, `dependent-rule`, `dependent-publication`, `dependent-generated-column`, or `partition-key` when a trigger's `UPDATE OF` list or `WHEN` condition names it, a rewrite rule reads it, a publication's column list or row filter names it, a generated column reads it, or it is in a partition key, before the route runs. The route's preflight still refuses table shapes and environments it cannot run against (`copy-and-swap-refused`); with the route opened, `migrate --alter --dry-run` runs that preflight under the run's own copy-and-swap flags, writing nothing, and ends in the same refusal, and `migrate --desired --dry-run` runs it the way the run's admission does, once against the live table under the run's flags, and ends in the run's whole-plan refusal. A `USING` expression is admitted only when the copy can reproduce it: immutable, naming only the retyped column, not the primary key (`shadow-statement-conversion`). A statement that also drops a column and adds one of the same name is refused when the copy cannot fill the new column — the primary key, a source identity column, or a column that refuses NULL with no default of its own or its domain's (`shadow-statement-readd`); a statement that also declares a new identity or `serial` column, re-added or kept, is refused with `shadow-statement-new-sequence` — see [limitations.md](limitations.md) A trigger whose PL/pgSQL function reads the column, which PostgreSQL records no dependency for, is named in the decision's `trigger_reads` with the line that reads it, and a trigger whose function cannot be checked in `unchecked_triggers`; neither changes the route. |
| `SET DEFAULT` / `DROP DEFAULT` / `DROP NOT NULL` | ✅ | native, as-is | Yes | Metadata-only. `DROP NOT NULL` is flagged **destructive**: `migrate` refuses it with `destructive-change` unless `--allow-destructive` names the table, and `migrate --desired` runs it only when `--expect-fingerprint` also pins the reviewed plan. A `migrate --desired` drop reads the object again under the table's lock and refuses with `dropped-object-drift`, dropping nothing, if its definition is not the one the reviewed plan carried. A `migrate --desired` `DROP NOT NULL` on a partitioned table with partitions, or on a table with inheritance children, refuses with `dropped-object-has-descendants`: a partition can hold a `NOT NULL` of its own on the column, which the plan did not review. |
| `SET NOT NULL` | ✅ | native, safer sequence | Yes | Executed as the native four-step pattern: `ADD CONSTRAINT ... CHECK (col IS NOT NULL) NOT VALID` → online `VALIDATE` → `SET NOT NULL` (catalog flip, PG 12+) → drop the scaffold check. A scaffold check an earlier run left is picked up where it stopped: the sequence starts at its `VALIDATE` and still drops it. `migrate --alter` on a column already `NOT NULL` on the table and every partition or inheritance child, with no scaffold check left, runs nothing and reports `executed-natively` with `already_not_null: true` and no `executed_sql`, after the same privilege check; the dry run classifies it `metadata-only` with no safer sequence |
Expand Down
Loading