Plans and lints production schema changes as expand/contract phases with the exact lock each PostgreSQL or MySQL 8 statement takes, lock_timeout guards, throttled batched backfills, dual-write and read cutover, and a verification plus reversal per phase.
Plans and lints production schema changes as expand/contract phases with the exact lock each PostgreSQL or MySQL 8 statement takes, lock_timeout guards, throttled batched backfills, dual-write and read cutover, and a verification plus reversal per phase, written to the Release Dossier. Includes a zero-dependency Postgres DDL linter. Use when someone asks "is this migration safe to run in prod", "add a NOT NULL column to a big table", "rename or retype this column without downtime", "backfill millions of rows", or when release-risk-classifier scores the data shape criterion R1 or higher. Do NOT use for greenfield schema design with no production rows - use database-schema instead; for a quick single-statement lock check outside a release, use migration-safety-checker; for deciding whether to revert after a failure, use rollback-or-roll-forward.This is the skill's description: the text your AI reads to decide when the skill applies.
zero-downtime-db-migrations/SKILL.md
---
name: zero-downtime-db-migrations
description: Plans and lints production schema changes as expand/contract phases with the exact lock each PostgreSQL or MySQL 8 statement takes, lock_timeout guards, throttled batched backfills, dual-write and read cutover, and a verification plus reversal per phase, written to the Release Dossier. Includes a zero-dependency Postgres DDL linter. Use when someone asks "is this migration safe to run in prod", "add a NOT NULL column to a big table", "rename or retype this column without downtime", "backfill millions of rows", or when release-risk-classifier scores the data shape criterion R1 or higher. Do NOT use for greenfield schema design with no production rows - use database-schema instead; for a quick single-statement lock check outside a release, use migration-safety-checker; for deciding whether to revert after a failure, use rollback-or-roll-forward.
---
# zero-downtime-db-migrations
Migrations cause outages two ways: the lock queue (a statement waiting for a strong lock blocks every query behind it, reads included) and app compatibility (the running version cannot read the new shape). Split every change into phases that are each safe alone, verified, and reversible.
## Inputs to collect
- Engine, major version, row counts and write rates.
- Whether the migration tool wraps files in a transaction (`CONCURRENTLY` needs that off), and the longest normal transaction on the primary: your DDL waits behind it.
- Dossier section 2 (tier, thresholds).
## Lock reference: PostgreSQL (checked against the PG 18 docs)
Only ACCESS EXCLUSIVE blocks plain SELECT; SHARE blocks writes; SHARE UPDATE EXCLUSIVE blocks neither.
| Statement | Lock and cost | Safe pattern |
|---|---|---|
| `CREATE INDEX` | SHARE: every write blocks for the whole build | `CREATE INDEX CONCURRENTLY` (SHARE UPDATE EXCLUSIVE). No transaction block; two scans; waits for older transactions, so `lock_timeout` and `statement_timeout` both apply and either can cancel it; one per table at a time; per partition on partitioned tables |
| Failed `CONCURRENTLY` build | INVALID index, still costs writes | check `indisvalid`; drop concurrently, retry |
| `ADD COLUMN` nullable or non-volatile DEFAULT (PG 11+) | ACCESS EXCLUSIVE, metadata only | safe with `lock_timeout`; `now()` is stable, so no rewrite |
| `ADD COLUMN` with volatile DEFAULT, stored generated, identity, or a domain type that has constraints | ACCESS EXCLUSIVE plus full table and index rewrite | add nullable, backfill, then set the default |Click to play with sound.