Repository navigation
feat(deploy): the migration becomes a pre-upgrade hook that may only add - #468
Merged
Merged
Conversation
athvin
force-pushed
the
bm/bluegreen-p9-colour
branch
from
November 4, 2026 23:52
40dc8de to
09b8d0a
Compare
athvin
force-pushed
the
bm/bluegreen-p10-migrate-hook
branch
from
November 4, 2026 23:52
93e8ec1 to
cf7d3df
Compare
athvin
force-pushed
the
bm/bluegreen-p10-migrate-hook
branch
from
November 5, 2026 00:19
cf7d3df to
f47798d
Compare
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
force-pushed
the
bm/bluegreen-p10-migrate-hook
branch
from
November 5, 2026 11:47
f47798d to
611a100
Compare
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.
Why it had to move
The init container on
web-apiwas only safe becauseRecreateguaranteed 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.mdrule 4 already named as its own condition:The colour dimension is that condition.
The objection is answered, not dismissed
job-db-migrate.yaml's header records why a pre-upgrade hook was rejected: it runs while the old pod still serves. That's true. The reason this one is safe is thater-server migrate --expect-additiveplans first and refuses, writing nothing, if the plan holds anything the reconciler would not auto-apply.So what it can execute is only
CREATE TABLEfor an absent relation andADD COLUMNfor 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_schemais six transactions, so by the time its phase-3 reconciler refuses, the baseline replay and theBeforeReconcilefixups have committed.Weight −5, and the rendered order
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.
Two choices worth reviewing
backoffLimit: 0, unlike the drizzle hook's 3. The expected failure here is a refusal — a deliberate state someone created by writing a breaking entity change — 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, since--atomicrolls 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.apimeans "the release this upgrade is about". Deriving it from a colour would be wrong in one of the two cutover phases — during the deploy phasecolor.activeis still the old colour, and during the flip phase the inactive one is.A probe found something worth fixing
I ran the hook's Job spec against the live kind cluster. It proved the wiring: image pulled, env and secret resolved,
er-apiservice account, command dispatched, exit 0 on a current store.But that cluster's image predates
--expect-additive, and the old binary — which took no arguments at all — accepted--does-not-existand exited 0 having done a normal migrate:A misspelled flag in a chart would silently turn this gate back into a plain apply, with the deploy looking identical. So the argument parsing moved into
migrate_plan::parse_migrate_argswhere the refusal is testable — four cases, including that order must not matter, since a scan stopping at the first recognised flag would accept--plan --oops.Being straight about what the probe did and didn't cover: it validated the Job wiring, not the new flag's behaviour. That seam is covered directly against a real Postgres by #456's own
pg_migrate_plan.rs, which was observed failing with its key assertion inverted.Docs revised in the same commit
Both claims became false. Rule 4 now describes the hook. And "What this does not do" no longer excludes blue-green across schema versions — what rules 5–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.
Verification
make checkgreen — 16migrate_planunit tests.helm lintclean;helm template+kubeconform -stricton the dev and kind profiles, both with zero init containers and the hook present.🤖 Generated with Claude Code