Repository navigation
feat(deploy): er-server migrate --plan, the additive/breaking verdict - #456
Merged
Merged
Conversation
athvin
force-pushed
the
bm/bluegreen-p5-migrate-plan
branch
from
November 3, 2026 05:52
ecc19ce to
8406738
Compare
This was referenced Nov 3, 2026
athvin
force-pushed
the
bm/bluegreen-p5-migrate-plan
branch
from
November 4, 2026 23:52
8406738 to
5354ff1
Compare
`docs/entity-framework-design.md` rule 9 names this as its own next step:
> A rollback across a breaking change is not protected by machinery yet: the
> image carries no `additive`/`breaking` label and CD does not refuse it,
> because there is no production environment to protect and no CD pipeline to
> put the gate in. That label is the next step when one exists.
This is the label. Three modes:
er-server migrate apply, as before
er-server migrate --plan [--json] report, write NOTHING; exit 3 if breaking
er-server migrate --expect-additive plan, refuse without writing, else apply
**This is not redundant with the refusal `ensure_schema` already carries**, and
the difference is the entire reason it exists. `ensure_schema` is six
transactions: phase 1 replays the baseline and COMMITS, phase 2 applies the
BeforeReconcile fixups and COMMITS, and only phase 3 reconciles and refuses. A
bare `migrate` against a store that is both behind and breaking converges part
of the way and then halts — right for a boot, wrong for a gate being asked "may
I deploy this?" before anything has been deployed.
Measured on one store state, which is now `pg_migrate_plan.rs`'s last phase:
| invocation | exit | `webhooks` table afterwards |
|---|---|---|
| `migrate --expect-additive` | 3 | absent — wrote nothing |
| `migrate` | 1 | **created** — phase 1 committed |
**Why not `er-entity migrate`,** which already plans exactly this: it loads the
catalog from `entities/` on disk, and the deployed image carries only the
`er-server` multicall binary (`rust/Dockerfile`). A gate that needs the
repository checked out cannot run in the pod being deployed. This reads the
catalog compiled into the image, which is also the only catalog whose answer
matters.
The classification is NOT re-derived. `er_entity_diff::plan_migration` is
already the authority for what the reconciler will and will not apply, already
a pure function, and already tested against a real Postgres; this reads the
live columns, calls it, and renders the answer.
Three details worth their comments:
- **`ahead` never changes the verdict**, and that is the whole basis of serving
one store from two versions: an older binary reads an ahead store correctly
because no statement uses `SELECT *` (E011). It IS reported, because
`additive` plus a non-empty `ahead` means you are looking at a rollback
rather than a fresh deploy, and the two want different attention.
- **Breaking dominates a mixed plan.** Applying the safe half would leave the
store between two shapes.
- **Exit 3, not 1**, so a gate can tell a refusal from a failure to reach the
database; 1 stays what every other error path in the binary means. An unknown
flag is refused rather than ignored — a gate invoked with a misspelled flag
that silently applied instead of planning is the worst outcome available.
What the plan deliberately does NOT cover: the named fixups. They exist to
perform what the declarative reconciler refuses, so the planner cannot see
them, and `additive` is a statement about the DIFF rather than about everything
the boot executes. That division is the point — a fixup is a named, reviewed,
ledgered step whose safety is argued in its own doc comment.
Verified: `make check` green. 12 unit cases over the verdict and both renderers
(including that a 1369-character generated statement is truncated rather than
flooding the report, and that truncation cannot split a multibyte character —
the generated DDL carries non-ASCII comment punctuation). The Postgres test was
**observed failing** with its key assertion inverted before being trusted, and
all four verdicts were exercised against a live store: additive on an empty
one, current after applying, breaking on a hand-retyped column, and ahead on a
hand-added one.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
athvin
force-pushed
the
bm/bluegreen-p5-migrate-plan
branch
from
November 5, 2026 00:19
5354ff1 to
2a8f450
Compare
athvin
pushed a commit
that referenced
this pull request
Nov 5, 2026
The init container on `web-api` was only safe because `Recreate` guaranteed the
old pod was already gone before it ran. Blue/green gives that guarantee up on
purpose — the point is that the old colour keeps serving — so the migration had
to become one the old code survives.
This is the swap `entity-framework-design.md` rule 4 already named as its own
condition: *"If replicas ever exceed one, the rule becomes expand-and-contract
and the init container is replaced by a hook that may only add."* The colour
dimension is that condition.
**The objection against a pre-upgrade hook is answered, not dismissed.**
`job-db-migrate.yaml`'s header records it: a pre-upgrade hook runs while the old
pod still serves. True, and the reason this one is safe is that
`er-server migrate --expect-additive` **plans first and refuses, writing
nothing**, if the plan holds anything the reconciler would not auto-apply. What
it can therefore execute is only `CREATE TABLE` for an absent relation and
`ADD COLUMN` for an absent nullable one — both of which the live colour
tolerates, because every statement names its columns (E011) and an older binary
reads an ahead store correctly.
That refusal is also what the bare command cannot give. `ensure_schema` is six
transactions: by the time its phase-3 reconciler refuses, the baseline replay
and the BeforeReconcile fixups have COMMITTED. Right for a boot, wrong for a
gate.
**Weight -5**: after the ExternalSecrets at -10 that project the DSN it needs,
before the drizzle hook at 0 — ordering the one that can REFUSE first, so a
breaking control plane stops the release before anything touches erweb.
Rendered order verified:
weight -10 pre-install,pre-upgrade ExternalSecret/er-erserver
weight -10 pre-install,pre-upgrade ExternalSecret/er-erweb
weight -5 pre-install,pre-upgrade Job/er-schema-migrate
weight 0 pre-install,pre-upgrade Job/er-web-db-migrate
weight 0 post-install,post-upgrade Job/er-tenant-migrate
**`backoffLimit: 0`**, unlike the drizzle hook's 3. The expected failure here is
a refusal — a deliberate state someone created — and retrying it three times
triples the time to a clear error while changing nothing. A transient blip
failing the release is the better trade, because `--atomic` rolls it back and
re-running is one command.
**Which image it runs: `images.api`, not a colour's pin.** The colour blocks say
what each DEPLOYMENT runs; `images.api` means "the release this upgrade is
about". Deriving it from a colour would be wrong in one of the two cutover
phases — during the deploy phase `color.active` is still the OLD colour, and
during the flip phase the inactive one is.
**A probe found something worth fixing.** Running the hook's Job spec against
the live kind cluster proved the wiring — image pulled, env and secret resolved,
`er-api` service account, command dispatched, exit 0 on a current store. But its
image predates `--expect-additive`, and the OLD binary, which took no arguments
at all, **accepted `--does-not-exist` and exited 0 having done a normal
migrate**. Silent acceptance of a misspelled flag in a chart would turn this
gate back into a plain apply with the deploy looking identical. So the argument
parsing moved into `migrate_plan::parse_migrate_args` where the refusal is
testable, with four cases including that order must not matter — a scan
stopping at the first RECOGNISED flag would accept `--plan --oops`.
Rule 4 and the "What this does not do" paragraph are revised in the same commit,
because both became false: blue/green across schema versions is no longer
excluded, and what rules 5 to 7 still stand in for is the LAKE half, which is
per-tenant and reconciled at each job's start rather than at the deploy
boundary. Canary remains excluded — traffic is all on one colour or all on the
other, never split by weight.
Includes #456's commit, because the chart cannot call a flag that does not
exist; it drops out when that merges first.
Verified: `make check` green (16 `migrate_plan` unit tests); `helm lint` clean;
`helm template` + `kubeconform -strict` on the dev and kind profiles, both with
zero init containers and the hook present. The hook's Job wiring probed on a
real cluster as above — and the one seam that probe could NOT cover, the new
flag's behaviour, is covered directly against a real Postgres by #456's own
pg test.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
athvin
pushed a commit
that referenced
this pull request
Nov 5, 2026
The init container on `web-api` was only safe because `Recreate` guaranteed the
old pod was already gone before it ran. Blue/green gives that guarantee up on
purpose — the point is that the old colour keeps serving — so the migration had
to become one the old code survives.
This is the swap `entity-framework-design.md` rule 4 already named as its own
condition: *"If replicas ever exceed one, the rule becomes expand-and-contract
and the init container is replaced by a hook that may only add."* The colour
dimension is that condition.
**The objection against a pre-upgrade hook is answered, not dismissed.**
`job-db-migrate.yaml`'s header records it: a pre-upgrade hook runs while the old
pod still serves. True, and the reason this one is safe is that
`er-server migrate --expect-additive` **plans first and refuses, writing
nothing**, if the plan holds anything the reconciler would not auto-apply. What
it can therefore execute is only `CREATE TABLE` for an absent relation and
`ADD COLUMN` for an absent nullable one — both of which the live colour
tolerates, because every statement names its columns (E011) and an older binary
reads an ahead store correctly.
That refusal is also what the bare command cannot give. `ensure_schema` is six
transactions: by the time its phase-3 reconciler refuses, the baseline replay
and the BeforeReconcile fixups have COMMITTED. Right for a boot, wrong for a
gate.
**Weight -5**: after the ExternalSecrets at -10 that project the DSN it needs,
before the drizzle hook at 0 — ordering the one that can REFUSE first, so a
breaking control plane stops the release before anything touches erweb.
Rendered order verified:
weight -10 pre-install,pre-upgrade ExternalSecret/er-erserver
weight -10 pre-install,pre-upgrade ExternalSecret/er-erweb
weight -5 pre-install,pre-upgrade Job/er-schema-migrate
weight 0 pre-install,pre-upgrade Job/er-web-db-migrate
weight 0 post-install,post-upgrade Job/er-tenant-migrate
**`backoffLimit: 0`**, unlike the drizzle hook's 3. The expected failure here is
a refusal — a deliberate state someone created — and retrying it three times
triples the time to a clear error while changing nothing. A transient blip
failing the release is the better trade, because `--atomic` rolls it back and
re-running is one command.
**Which image it runs: `images.api`, not a colour's pin.** The colour blocks say
what each DEPLOYMENT runs; `images.api` means "the release this upgrade is
about". Deriving it from a colour would be wrong in one of the two cutover
phases — during the deploy phase `color.active` is still the OLD colour, and
during the flip phase the inactive one is.
**A probe found something worth fixing.** Running the hook's Job spec against
the live kind cluster proved the wiring — image pulled, env and secret resolved,
`er-api` service account, command dispatched, exit 0 on a current store. But its
image predates `--expect-additive`, and the OLD binary, which took no arguments
at all, **accepted `--does-not-exist` and exited 0 having done a normal
migrate**. Silent acceptance of a misspelled flag in a chart would turn this
gate back into a plain apply with the deploy looking identical. So the argument
parsing moved into `migrate_plan::parse_migrate_args` where the refusal is
testable, with four cases including that order must not matter — a scan
stopping at the first RECOGNISED flag would accept `--plan --oops`.
Rule 4 and the "What this does not do" paragraph are revised in the same commit,
because both became false: blue/green across schema versions is no longer
excluded, and what rules 5 to 7 still stand in for is the LAKE half, which is
per-tenant and reconciled at each job's start rather than at the deploy
boundary. Canary remains excluded — traffic is all on one colour or all on the
other, never split by weight.
Includes #456's commit, because the chart cannot call a flag that does not
exist; it drops out when that merges first.
Verified: `make check` green (16 `migrate_plan` unit tests); `helm lint` clean;
`helm template` + `kubeconform -strict` on the dev and kind profiles, both with
zero init containers and the hook present. The hook's Job wiring probed on a
real cluster as above — and the one seam that probe could NOT cover, the new
flag's behaviour, is covered directly against a real Postgres by #456's own
pg test.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
athvin
pushed a commit
that referenced
this pull request
Nov 5, 2026
The init container on `web-api` was only safe because `Recreate` guaranteed the
old pod was already gone before it ran. Blue/green gives that guarantee up on
purpose — the point is that the old colour keeps serving — so the migration had
to become one the old code survives.
This is the swap `entity-framework-design.md` rule 4 already named as its own
condition: *"If replicas ever exceed one, the rule becomes expand-and-contract
and the init container is replaced by a hook that may only add."* The colour
dimension is that condition.
**The objection against a pre-upgrade hook is answered, not dismissed.**
`job-db-migrate.yaml`'s header records it: a pre-upgrade hook runs while the old
pod still serves. True, and the reason this one is safe is that
`er-server migrate --expect-additive` **plans first and refuses, writing
nothing**, if the plan holds anything the reconciler would not auto-apply. What
it can therefore execute is only `CREATE TABLE` for an absent relation and
`ADD COLUMN` for an absent nullable one — both of which the live colour
tolerates, because every statement names its columns (E011) and an older binary
reads an ahead store correctly.
That refusal is also what the bare command cannot give. `ensure_schema` is six
transactions: by the time its phase-3 reconciler refuses, the baseline replay
and the BeforeReconcile fixups have COMMITTED. Right for a boot, wrong for a
gate.
**Weight -5**: after the ExternalSecrets at -10 that project the DSN it needs,
before the drizzle hook at 0 — ordering the one that can REFUSE first, so a
breaking control plane stops the release before anything touches erweb.
Rendered order verified:
weight -10 pre-install,pre-upgrade ExternalSecret/er-erserver
weight -10 pre-install,pre-upgrade ExternalSecret/er-erweb
weight -5 pre-install,pre-upgrade Job/er-schema-migrate
weight 0 pre-install,pre-upgrade Job/er-web-db-migrate
weight 0 post-install,post-upgrade Job/er-tenant-migrate
**`backoffLimit: 0`**, unlike the drizzle hook's 3. The expected failure here is
a refusal — a deliberate state someone created — and retrying it three times
triples the time to a clear error while changing nothing. A transient blip
failing the release is the better trade, because `--atomic` rolls it back and
re-running is one command.
**Which image it runs: `images.api`, not a colour's pin.** The colour blocks say
what each DEPLOYMENT runs; `images.api` means "the release this upgrade is
about". Deriving it from a colour would be wrong in one of the two cutover
phases — during the deploy phase `color.active` is still the OLD colour, and
during the flip phase the inactive one is.
**A probe found something worth fixing.** Running the hook's Job spec against
the live kind cluster proved the wiring — image pulled, env and secret resolved,
`er-api` service account, command dispatched, exit 0 on a current store. But its
image predates `--expect-additive`, and the OLD binary, which took no arguments
at all, **accepted `--does-not-exist` and exited 0 having done a normal
migrate**. Silent acceptance of a misspelled flag in a chart would turn this
gate back into a plain apply with the deploy looking identical. So the argument
parsing moved into `migrate_plan::parse_migrate_args` where the refusal is
testable, with four cases including that order must not matter — a scan
stopping at the first RECOGNISED flag would accept `--plan --oops`.
Rule 4 and the "What this does not do" paragraph are revised in the same commit,
because both became false: blue/green across schema versions is no longer
excluded, and what rules 5 to 7 still stand in for is the LAKE half, which is
per-tenant and reconciled at each job's start rather than at the deploy
boundary. Canary remains excluded — traffic is all on one colour or all on the
other, never split by weight.
Includes #456's commit, because the chart cannot call a flag that does not
exist; it drops out when that merges first.
Verified: `make check` green (16 `migrate_plan` unit tests); `helm lint` clean;
`helm template` + `kubeconform -strict` on the dev and kind profiles, both with
zero init containers and the hook present. The hook's Job wiring probed on a
real cluster as above — and the one seam that probe could NOT cover, the new
flag's behaviour, is covered directly against a real Postgres by #456's own
pg test.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
athvin
added a commit
that referenced
this pull request
Nov 5, 2026
…add (#468) The init container on `web-api` was only safe because `Recreate` guaranteed the old pod was already gone before it ran. Blue/green gives that guarantee up on purpose — the point is that the old colour keeps serving — so the migration had to become one the old code survives. This is the swap `entity-framework-design.md` rule 4 already named as its own condition: *"If replicas ever exceed one, the rule becomes expand-and-contract and the init container is replaced by a hook that may only add."* The colour dimension is that condition. **The objection against a pre-upgrade hook is answered, not dismissed.** `job-db-migrate.yaml`'s header records it: a pre-upgrade hook runs while the old pod still serves. True, and the reason this one is safe is that `er-server migrate --expect-additive` **plans first and refuses, writing nothing**, if the plan holds anything the reconciler would not auto-apply. What it can therefore execute is only `CREATE TABLE` for an absent relation and `ADD COLUMN` for an absent nullable one — both of which the live colour tolerates, because every statement names its columns (E011) and an older binary reads an ahead store correctly. That refusal is also what the bare command cannot give. `ensure_schema` is six transactions: by the time its phase-3 reconciler refuses, the baseline replay and the BeforeReconcile fixups have COMMITTED. Right for a boot, wrong for a gate. **Weight -5**: after the ExternalSecrets at -10 that project the DSN it needs, before the drizzle hook at 0 — ordering the one that can REFUSE first, so a breaking control plane stops the release before anything touches erweb. Rendered order verified: weight -10 pre-install,pre-upgrade ExternalSecret/er-erserver weight -10 pre-install,pre-upgrade ExternalSecret/er-erweb weight -5 pre-install,pre-upgrade Job/er-schema-migrate weight 0 pre-install,pre-upgrade Job/er-web-db-migrate weight 0 post-install,post-upgrade Job/er-tenant-migrate **`backoffLimit: 0`**, unlike the drizzle hook's 3. The expected failure here is a refusal — a deliberate state someone created — and retrying it three times triples the time to a clear error while changing nothing. A transient blip failing the release is the better trade, because `--atomic` rolls it back and re-running is one command. **Which image it runs: `images.api`, not a colour's pin.** The colour blocks say what each DEPLOYMENT runs; `images.api` means "the release this upgrade is about". Deriving it from a colour would be wrong in one of the two cutover phases — during the deploy phase `color.active` is still the OLD colour, and during the flip phase the inactive one is. **A probe found something worth fixing.** Running the hook's Job spec against the live kind cluster proved the wiring — image pulled, env and secret resolved, `er-api` service account, command dispatched, exit 0 on a current store. But its image predates `--expect-additive`, and the OLD binary, which took no arguments at all, **accepted `--does-not-exist` and exited 0 having done a normal migrate**. Silent acceptance of a misspelled flag in a chart would turn this gate back into a plain apply with the deploy looking identical. So the argument parsing moved into `migrate_plan::parse_migrate_args` where the refusal is testable, with four cases including that order must not matter — a scan stopping at the first RECOGNISED flag would accept `--plan --oops`. Rule 4 and the "What this does not do" paragraph are revised in the same commit, because both became false: blue/green across schema versions is no longer excluded, and what rules 5 to 7 still stand in for is the LAKE half, which is per-tenant and reconciled at each job's start rather than at the deploy boundary. Canary remains excluded — traffic is all on one colour or all on the other, never split by weight. Includes #456's commit, because the chart cannot call a flag that does not exist; it drops out when that merges first. Verified: `make check` green (16 `migrate_plan` unit tests); `helm lint` clean; `helm template` + `kubeconform -strict` on the dev and kind profiles, both with zero init containers and the hook present. The hook's Job wiring probed on a real cluster as above — and the one seam that probe could NOT cover, the new flag's behaviour, is covered directly against a real Postgres by #456's own pg test. Co-authored-by: bmoore813 <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
docs/entity-framework-design.mdrule 9 names this as its own next step:This is the label.
This is not redundant with the refusal
ensure_schemaalready hasThat's the entire reason it exists, and it took measuring to be sure of.
ensure_schemais six transactions: phase 1 replays the baseline and commits, phase 2 applies theBeforeReconcilefixups and commits, and only phase 3 reconciles and refuses. So a baremigrateagainst a store that is both behind and breaking converges part of the way and then halts. That is right for a boot — converge as far as is safe, then fail loudly — and wrong for a gate being asked "may I deploy this?" before anything has been deployed.Measured against one store state (dropped
webhooksso phase 1 has work, plus a retyped column so phase 3 refuses). This is now the last phase ofpg_migrate_plan.rs:webhooksafterwardsmigrate --expect-additivemigrateWhy not
er-entity migrate, which already plans exactly thisIt loads the catalog from
entities/on disk, and the deployed image carries only theer-servermulticall binary (rust/Dockerfile:69-72). A gate that needs the repository checked out cannot run in the pod being deployed. This reads the catalog compiled into the image — which is also the only catalog whose answer matters.The classification is not re-derived.
er_entity_diff::plan_migrationis already the authority for what the reconciler will and won't apply, already a pure function, already tested against a real Postgres. This reads the live columns, calls it, and renders the answer.Three details worth their comments
aheadnever changes the verdict, and that's the whole basis of serving one store from two versions: an older binary reads an ahead store correctly because no statement usesSELECT *(E011). It is reported, becauseadditiveplus a non-emptyaheadmeans you're looking at a rollback rather than a fresh deploy, and the two want different attention.1stays what every other error path in the binary means. An unknown flag is refused rather than ignored — a gate invoked with a misspelled flag that silently applied instead of planning is the worst outcome available here.What the plan deliberately does not cover
The named fixups. They exist precisely to perform what the declarative reconciler refuses (
0003_per_dataset_locksdrops indexes and a constraint), so the planner cannot see them, andadditiveis a statement about the diff rather than about everything the boot executes.That division is the point rather than a gap: a fixup is a named, reviewed, ledgered step whose safety is argued in its own doc comment, while the diff is the part generated from
entities/that nobody reads line by line.Verification
make checkgreen.additiveon an empty one (22 statements planned, 0 tables created),currentafter applying,breakingon a hand-retyped column,aheadon a hand-added one.The chart will use
--expect-additivewhen the migration moves from the init container to a pre-upgrade hook; nothing calls it yet, so this lands inert.🤖 Generated with Claude Code