Skip to content

fix(ci): skip the snapshot and apply when no migrations are pending - #295

Merged
nourshoreibah merged 1 commit into
mainfrom
fix/skip-noop-migrate
Jul 29, 2026
Merged

fix(ci): skip the snapshot and apply when no migrations are pending#295
nourshoreibah merged 1 commit into
mainfrom
fix/skip-noop-migrate

Conversation

@nourshoreibah

Copy link
Copy Markdown
Collaborator

Why

The migrate job fires whenever a push touches db/migrations/** and on every manual dispatch — a dispatch has no diff, so detect-changes assumes migrate=true:

if [[ "$EVENT" == "workflow_dispatch" ]]; then
  migrate=true

Neither condition means anything is actually pending; CI can't know that until it connects to the database.

With nothing pending the apply was already a harmless no-op (database is already up to date), but the job still took an RDS snapshot and waited for it — 1-2 minutes per deploy, and junk churning through the 5-snapshot retention window. Both of the manual dispatches on 566ffa4 hit exactly this path.

What

migrate:status already runs as a read-only preflight and already prints the count, so parse it and gate on it:

  • snapshot and apply are skipped when pending == 0
  • unparseable output falls through as 1, so the safe path (snapshot first) is taken
  • pruning only runs when a snapshot was actually created
  • the baseline tripwire still runs unconditionally

Reporting

up being skipped is a success as far as the deploy is concerned, so the result artifact and the Slack step report success rather than the raw skipped — otherwise slack-deploy's finalize would mark the whole run failed, since it fails on any .meta that isn't success. The Slack step name and the job summary say "nothing pending" instead of claiming migrations were applied.

A missing migrate.log is fine: the result step falls back to status.log, and slack-deploy already wraps its details-file read in a try/catch.

Verification

The count parser, against real migrate:status output:

status output parsed
1 applied, 0 pending 0 → skips
1 applied, 1 pending 1 → runs
3 applied, 12 pending 12 → runs
garbage / no count 1 → runs (safe default)

Resulting step conditions:

Pending migrations (read-only preflight)      if=-
Snapshot production before migrating          if=pending != '0'
Apply migrations                              if=pending != '0'
Nothing to apply                              if=pending == '0'
Prune old pre-migration snapshots (keep 5)    if=always() && snapshot.outcome == 'success'

Production was adopted separately (ledger now holds 0000_baseline_schema, 1 applied, 0 pending), so on current main this job takes the pending == 0 path — which is what this PR makes cheap.

🤖 Generated with Claude Code

The migrate job runs whenever a push touches db/migrations/** and on every manual
dispatch (a dispatch has no diff, so detect-changes assumes migrate=true). Neither
means anything is actually pending -- CI can't know that until it connects.

With nothing pending the apply was already a harmless no-op, but the job still took
an RDS snapshot and waited for it: 1-2 minutes per deploy, and junk churning through
the 5-snapshot retention.

The migrate:status preflight already knows the count, so parse it and gate the
snapshot and the apply on it. Unparseable output falls through as "1" so the safe
path (snapshot first) is taken. Pruning now only runs when a snapshot was actually
created.

`up` being skipped is a success as far as the deploy is concerned, so the result
artifact and the Slack step report success rather than the raw 'skipped' -- otherwise
slack-deploy's finalize would mark the whole run failed. The Slack step and the job
summary say "nothing pending" instead of claiming migrations were applied.

The baseline tripwire still runs unconditionally.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@nourshoreibah nourshoreibah added the no-review The PR review bot won't run label Jul 29, 2026
@nourshoreibah
nourshoreibah marked this pull request as ready for review July 29, 2026 05:14
@nourshoreibah
nourshoreibah merged commit d222774 into main Jul 29, 2026
19 checks passed
@nourshoreibah
nourshoreibah deleted the fix/skip-noop-migrate branch July 29, 2026 05:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-review The PR review bot won't run

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant