Skip to content

feat(deploy): defer a shared target that brings migrations to a reviewer, expand the schema there, and alias a proved target - #274

Merged
aRustyDev merged 2 commits into
mainfrom
feat/target-migrate
Nov 17, 2026
Merged

aRustyDev merged 2 commits into
mainfrom
feat/target-migrate

Conversation

@aRustyDev

Copy link
Copy Markdown
Owner

The script half of deploying release candidates as targets (#195 stage E, ADR-0111). It changes scripts/deploy-target.sh
only; no workflow runs it yet. The workflow half is the next PR, stacked on this one.

Why

A shared target uses production's database. ADR-0111 decided that a shared target bringing a new migration waits for a
reviewer, and that contract migrations happen only in production's deploy. The script now knows when a candidate brings a
migration, and migrates only where it is allowed to.

What changes in deploy-target.sh

New step 2b, before anything is created:

  • Reads what production runs: wrangler's deployments and versions of the production Worker, through active-version.py,
    the same reading deploy-worker.sh uses. A target is a Preview of production, so production must be deployed.
  • Classifies the candidate against production's live commit with classify-deploy.sh, fetching that commit by its sha
    if needed, as deploy-worker.sh does. A live state it can't read (split or unknown) counts as bringing migrations.
  • What happens next depends on that:
The candidate Without ALLOW_MIGRATE With ALLOW_MIGRATE=true
brings migrations deferred=true, exit 0, nothing done: the cue for the reviewer-gated job migrate-ci.sh --no-contract first, seeing only the database's secrets, then the deploy
brings none deploys deploys, without migrating

New step 9: TARGET_ALIAS points an alias of the policy, such as staging, at the target. It's set last, after the
smoke and its control, so a candidate becomes staging only once proved. An alias that doesn't stick fails the deploy and
removes the target. An alias the policy lacks is refused before anything is asked.

New outputs: deferred and migrations_changed.

Tests

test-deploy-target.sh, under dash: 161 checks pass, 40 of them new.

  • The fakes:
    • the wrangler fake now answers deployments list and versions list for production: one tagged version, none, split,
      or a listing that fails;
    • a fake classifier and a fake migration record their arguments and the secrets they could see.
  • What the new tests show:
    • the classifier is asked with (production's commit, the candidate);
    • a candidate with migrations is deferred: no Preview, no migration, nothing left;
    • a split production is deferred without asking the classifier;
    • with ALLOW_MIGRATE, the migration runs with --no-contract, before the Preview, and is the only step that sees the
      database's secrets;
    • with nothing to migrate, nothing is migrated;
    • an undeployed production, a failed listing, a failed classifier and a failed migration each stop before any Preview;
    • the alias is set last and names the target, and one that doesn't stick removes the target.

Hand mutants: 14 versions of the new code with a planted bug; each one fails the tests.

Also passing: every deps step, every ci-scripts test (40, each on its own under dash), and actionlint.

Refs #195

🤖 Generated with Claude Code

aRustyDev and others added 2 commits November 17, 2026 00:48
…wer, expand the schema there, and alias a proved target

The script half of wiring release candidates as targets (#195 stage E, ADR-0111). A shared target uses production's database, and
ADR-0111 decided that one bringing a new migration waits for a reviewer. scripts/deploy-target.sh now knows when that is, and does
the migration only where it may.

New step 2b, before anything is created:
- It reads what production runs: wrangler's deployments and versions of the production Worker, through
  .github/scripts/active-version.py, the same reading deploy-worker.sh uses. A target is a Preview OF production, so production
  must be deployed (exit 1 otherwise).
- It classifies the candidate against production's live commit, with .github/scripts/classify-deploy.sh, fetching that commit by
  its sha when no branch holds it, as deploy-worker.sh does. A live state it cannot read (split, unknown) counts as bringing
  migrations.
- Migrations, without ALLOW_MIGRATE=true: `deferred=true`, exit 0, nothing done. That is the cue for the job whose environment
  has reviewers and the database route.
- Migrations, with ALLOW_MIGRATE=true: scripts/migrate-ci.sh --no-contract runs before the Preview. A contract migration stays
  production's deploy's alone. It sees only the database's secrets (DATABASE_URL and the tunnel's service token), and nothing
  else sees them.
- No migrations: no migration, even with ALLOW_MIGRATE.

New step 9: TARGET_ALIAS (one of the policy's aliases, checked before anything is asked) points that alias at the target with
flagship.py alias, LAST, after the smoke and its control. A release candidate becomes `staging` only once proved. An alias that
does not stick fails the deploy, and the target is removed like any other failure.

Outputs: deferred and migrations_changed join the others.

Tests (test-deploy-target.sh, under dash: 161 passed, 40 new). The fakes now answer `deployments list` and `versions list` for
production (one tagged version, none, split, a listing that fails), and add a classifier and a migration that record their
arguments and the secrets they saw. Cases:
- the classifier asked with (production's commit, the candidate);
- no migration when there is none, even with ALLOW_MIGRATE;
- a candidate with migrations deferred, with no Preview, no migration and nothing left;
- a split production deferred without asking the classifier;
- with ALLOW_MIGRATE: `--no-contract`, before the Preview, the database's secrets seen by the migration only, and the target
  right afterwards;
- an undeployed production, a failed listing, a failed classifier and a failed migration, each failing before any Preview;
- the alias set last, naming the target; an alias that does not stick removing the target;
- the new usage errors.
14 hand mutants of the new code each fail it.

Not here: the workflow that runs it (deploy.yml's switch, its two jobs and environments), which comes next.

Refs: #195
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant