Skip to content
Merged
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
33 changes: 31 additions & 2 deletions docs/cli-output-examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ in `detail`. The set is closed and pinned by test (`verdict.Reasons()`).
| `destructive-change` | The change discards live data or structure — a dropped column, constraint, index, or `NOT NULL`. `migrate --alter` runs it only when `--allow-destructive` names the table, and a refused statement that drops a column and adds it back carries the `alter-column-type-in-place` guidance; a desired-state plan that drops anything is refused whole until the run pins the reviewed plan with `--expect-fingerprint` and names its table with `--allow-destructive` ([Apply a reviewed drop](cli.md#apply-a-reviewed-drop), [execution model](execution-model.md)). |
| `plan-fingerprint-mismatch` | The plan recomputed at execution time does not carry the pinned fingerprint: the plan a reviewer approved is not the plan that would execute, so nothing runs ([execution model](execution-model.md)). Cause `pinned-refused-preview`: the pin is a dry run's refused preview of the plan, which no run executes; pin the plan's own fingerprint, which the detail names. |
| `declarative-foreign-key` | The desired-state plan drops a foreign key it does not run. Cause `changed-foreign-key`: the file changes the key under the same name on a partitioned table, where the new key cannot be added in the same statement; declare it under a new name. Cause `column-first-foreign-key`: the plan also retypes a column, or drops one beside an added column that may rewrite the table, so it drops the key before the new one is added; apply the column change on its own first, then the foreign key change. Cause `undeclarable-foreign-key`: a desired file cannot declare the key (one into a schema `ForeignKeySchemas` does not list, or onto its own table through a standalone unique index); the plan still shows the statement, and `migrate --alter` runs it. |
| `copy-and-swap-refused` | The change routes to copy-and-swap and the route's own gates declined it: the run did not open the route (the route is in preview; cause `copy-and-swap-not-enabled`, class `capability-boundary`, raised before the route's preflight runs or anything is written — pass `--copy-and-swap`), the closed route was reached only by retyping a column a partitioned parent's partitioned index reads, which the route would refuse as a partitioned parent once opened (cause `partitioned-index-rebuild`, class `capability-boundary` — drop the index in a run of its own, then retype the column and recreate the index, as the `detail` says; [limitations](limitations.md)), a copy-and-swap run stopped on the table keeps any other statement from running (cause `copy-and-swap-run-stopped`, class `environmental` — run the stopped statement again to finish it, with `--block-writes` when it blocked writes, whose verdict then carries `writes_blocked: true`, or, before its cutover, start it over with `--restart SCHEMA.TABLE` or abandon it with `pg-sprite discard SCHEMA.TABLE`), the preflight found a table shape or an environment it cannot run against, or a shadow operation refused mid-run to keep an invariant. A run whose table was changed by hand while it ran or stood stopped cannot go on: its cutover is refused with `cutover-schema-drift` or `cutover-fidelity-drift`, its resume with `resume-source-changed` (class `environmental`), and the `detail` names the shadow, the fence or the replication slot and publication, and the checkpoint row the run leaves, and the `--restart` and `discard` commands past them. The verdict's `cause` carries the route's own refusal token (`copy-and-swap-…` from the gate and the preflight, `shadow-…` from the shadow operations) and `class` its routing class; [refusal-classes.md](refusal-classes.md#copy-and-swap-refused-keyed-on-copyswaprefusalcause) lists every cause. A table refused for its shape also carries `causes`: every shape cause it has, the verdict's `cause` first, each an object with `cause`, `class`, `detail` (naming the triggers, foreign keys, views, publications, or other objects behind it), and `next_step`, so one run reports them all ([example](copy-and-swap.md#what-each-run-needs)); a `migrate --desired` result refused whole for the table's shape carries the same `causes`, and so does its `--dry-run`, which runs the route's preflight against the live table as the run's admission does. A table refused with `copy-and-swap-pk-unsupported` because it has no primary key also carries `"guidance": "add-integer-primary-key"`, and its `detail` links the [steps to add one online](primary-keys.md#add-a-primary-key-online). |
| `copy-and-swap-refused` | The change routes to copy-and-swap and the route's own gates declined it: the run did not open the route (the route is in preview; cause `copy-and-swap-not-enabled`, class `capability-boundary`, raised before the route's preflight runs or anything is written — pass `--copy-and-swap`), the closed route was reached only by retyping a column a partitioned parent's partitioned index reads, which the route would refuse as a partitioned parent once opened (cause `partitioned-index-rebuild`, class `capability-boundary` — drop the index in a run of its own, then retype the column and recreate the index, as the `detail` says; [limitations](limitations.md)), a copy-and-swap run stopped on the table keeps any other statement from running (cause `copy-and-swap-run-stopped`, class `environmental` — run the stopped statement again to finish it, with `--block-writes` when it blocked writes, whose verdict then carries `writes_blocked: true`, or, before its cutover, start it over with `--restart SCHEMA.TABLE` or abandon it with `pg-sprite discard SCHEMA.TABLE`), the preflight found a table shape or an environment it cannot run against, or a shadow operation refused mid-run to keep an invariant. A run whose table was changed by hand while it ran or stood stopped cannot go on: its cutover is refused with `cutover-schema-drift` or `cutover-fidelity-drift`, its resume with `resume-source-changed` (class `environmental`), and the `detail` names the shadow, the fence or the replication slot and publication, and the checkpoint row the run leaves, and the `--restart` and `discard` commands past them; the verdict's `standing_run` names the same leftovers typed ([example](#refused-the-table-changed-under-a-stopped-copy-and-swap-run-resume-source-changed--exit-2)). The verdict's `cause` carries the route's own refusal token (`copy-and-swap-…` from the gate and the preflight, `shadow-…` from the shadow operations) and `class` its routing class; [refusal-classes.md](refusal-classes.md#copy-and-swap-refused-keyed-on-copyswaprefusalcause) lists every cause. A table refused for its shape also carries `causes`: every shape cause it has, the verdict's `cause` first, each an object with `cause`, `class`, `detail` (naming the triggers, foreign keys, views, publications, or other objects behind it), and `next_step`, so one run reports them all ([example](copy-and-swap.md#what-each-run-needs)); a `migrate --desired` result refused whole for the table's shape carries the same `causes`, and so does its `--dry-run`, which runs the route's preflight against the live table as the run's admission does. A table refused with `copy-and-swap-pk-unsupported` because it has no primary key also carries `"guidance": "add-integer-primary-key"`, and its `detail` links the [steps to add one online](primary-keys.md#add-a-primary-key-online). |
| `create-collision` | The greenfield create plan's table name or a claimed index, constraint-index, or sequence name is occupied. Nothing runs; re-derive the plan against the live catalog to see what holds the name, then drop or rename the occupant, name a constraint's index explicitly, or for a sequence use an explicitly named sequence or a non-serial column — re-planning alone reproduces the refusal. Catalog absence checks handle existing occupants. Duplicate-name SQLSTATEs backstop races for explicit names; for server-chosen names, the probe narrows the race to the time-of-check window, and after the `CREATE TABLE` commits the executor reads the constraint-index and sequence names the table actually owns and compares them against the claimed first-choice names — a name taken inside the window makes the server pick a suffixed replacement, which surfaces as a typed `create-name-mismatch` failure at step 1 with the born table left in place for an operator to rename the relation or drop, then re-diff. |

Two codes that look like refusals are not: `create-name-mismatch` and
Expand Down Expand Up @@ -557,7 +557,14 @@ shadow from the table as it is now, keeping the column added by hand, and
`discard` drops what the run left without running the change. A run that was
still in progress when the table changed stops at its cutover instead, with
cause `cutover-schema-drift`, and its detail adds the same account. A consumer
branches on the `cause` field, not on the detail's wording:
branches on the `cause` field, not on the detail's wording. What the run leaves
is also the verdict's `standing_run`, so a consumer can warn that the slot
retains WAL without parsing the detail: `shadow`, quoted as `DROP TABLE` takes
it; `hold`, `slot` here, or `write-fence` for a run that blocked writes, which
names no `slot` or `publication`; the slot as `pg_replication_slots` names it
and the publication quoted; and the checkpoint row's `phase`. Every refusal
that names what a stopped run leaves carries it, the cutover's drift refusals
included. At a terminal the refusal reads:

```console
$ pg-sprite migrate --alter 'ALTER TABLE orders ALTER COLUMN user_id TYPE bigint' --copy-and-swap --free-disk 10GiB
Expand All @@ -568,6 +575,28 @@ refused (copy-and-swap-refused)
detail: public.orders changed since this run built its shadow (for example a column or index added by hand); the stopped run cannot resume, and it leaves shadow table public._pgsprite_c74da4a21f58f903_new, replication slot pgsprite_a725d037, which retains WAL on the server until it is dropped, publication pgsprite_a725d037, and the checkpoint row in phase verifying; start over by running the same pg-sprite migrate command with --restart public.orders, or abandon the run without running the change with pg-sprite discard public.orders
```

and with `--json`:

```console
$ pg-sprite migrate --alter 'ALTER TABLE orders ALTER COLUMN user_id TYPE bigint' --copy-and-swap --free-disk 10GiB --json
{
"outcome": "refused",
"reason": "copy-and-swap-refused",
"class": "environmental",
"cause": "resume-source-changed",
"statement": "ALTER TABLE public.orders ALTER COLUMN user_id TYPE bigint",
"table": "public.orders",
"detail": "public.orders changed since this run built its shadow (for example a column or index added by hand); the stopped run cannot resume, and it leaves shadow table public._pgsprite_c74da4a21f58f903_new, replication slot pgsprite_a725d037, which retains WAL on the server until it is dropped, publication pgsprite_a725d037, and the checkpoint row in phase verifying; start over by running the same pg-sprite migrate command with --restart public.orders, or abandon the run without running the change with pg-sprite discard public.orders",
"standing_run": {
"shadow": "\"public\".\"_pgsprite_c74da4a21f58f903_new\"",
"hold": "slot",
"slot": "pgsprite_a725d037",
"publication": "\"pgsprite_a725d037\"",
"phase": "verifying"
}
}
```

### Refused: a stopped run of the other mode (`copy-and-swap-refused`) — exit 2

A run resumes only in the mode it started in. Here a `--block-writes` run of
Expand Down
8 changes: 6 additions & 2 deletions docs/invariants.md
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,10 @@ JSON-encoded proof the row carries (`resume-row-mismatch` otherwise, wrapping a
is the derived one, as `copy-conversion-drift` for a proof that differs in its conversion fingerprint alone does, except that a row whose shadow fingerprint matches and
whose source fingerprint, or source relation or source fidelity snapshot alone, differs is `resume-source-changed`: the source was changed under
the stopped run, the environment's doing rather than the row's, and the refusal wraps a `StandingRunError` naming the shadow,
the fence or slot and publication, and the row the run leaves for a restart or `Runner.Discard`;
the fence or slot and publication, and the row the run leaves for a restart or `Runner.Discard`,
which `migrate` also carries on the verdict as `standing_run`
(`TestMigrateJSONNamesTheSlotAStoppedLiveRunLeaves`,
`TestMigrateJSONNamesTheWriteFenceAStoppedBlockedWritesRunLeaves`);
`checkRowDescribes`, refuses-to-resume-a-stopped-run-whose-source-changed-by-hand test) — and refuses a relation
under the shadow's name that no row records (`shadow-unrecorded`), since the row is the only
record of which statement a shadow embodies, and a row whose swap has not committed and whose
Expand Down Expand Up @@ -1764,7 +1767,8 @@ statement retyped, which the server re-derives for the new type; an operator cla
written in the index still has to agree) and lists the sequences the swap must re-own. A
`Runner` the gate stops on `cutover-schema-drift` or `cutover-fidelity-drift` cannot go on, so it returns the refusal with a
`StandingRunError` beside it (`withStandingRun`) naming the shadow, the fence or slot and publication, and the checkpoint row it
leaves for a restart or `Runner.Discard` (cutover-drift-names-what-the-live-run-leaves test). Before that,
leaves for a restart or `Runner.Discard`, which `migrate` also carries on the verdict as `standing_run`
(cutover-drift-names-what-the-live-run-leaves test, `TestRunCopySwapCutoverDriftNamesWhatTheLiveRunLeaves`). Before that,
`pkg/schemachange` refuses to build a shadow the source's owner does not own, and refuses to inspect or drop anything under the
shadow's name that is not a plain table the source's owner owns (an inspected shadow must also
still draw each identity default from the source's sequence). *Source:*
Expand Down
Loading