- Home
- Skills
- Data & Databases
- Zero-Downtime DB Migration Safety Gate
Works with the AI Agents you already use
Zero-Downtime DB Migration Safety Gate
Block table-locking PostgreSQL/MySQL DDL and breaking schema drops before they take down production during rolling deploys—with a read-only analyzer, Expand-and-Contract rewrites, and rollback runbooks.
$7
Zero-Downtime DB Migration Safety Gate
Example session with this skill installed
Review our pending Postgres migration migrations/20261124_alter_orders.sql and k8s/deployment.yaml for zero-downtime release safety on a 50M-row orders table. Give me a GO/NO-GO verdict and rewrite it into a safe Expand-and-Contract plan before modifying any files.
- Read your context and instructions
- Compiled the zero-downtime db migration
Zero-Downtime DB Migration & Release Safety Gate
Release Verdict: NO-GO · Findings: 4 Critical · 4 High · 1 Medium (Postgres dialect)
| Rule | Severity | Location | Lock / Risk Impact | Zero-Downtime Fix |
|---|---|---|---|---|
DBM-001 | Critical | alter_orders.sql:4 | CREATE INDEX holds SHARE lock (blocks all INSERT/UPDATE/DELETE) | Use CREATE INDEX CONCURRENTLY outside transaction |
DBM-002 | Critical | alter_orders.sql:9 | DROP COLUMN legacy_status breaks N-1 app pods mid-rollout | Stop reading column in Release N; drop in Release N+1 |
DBM-004 | Critical | alter_orders.sql:12 | ALTER COLUMN total TYPE numeric(12,2) rewrites entire 50M-row table | Add new column, dual-write, batch-backfill, swap |
DBM-006 | High | alter_orders.sql:16 | ADD CONSTRAINT ... CHECK scans full table under ACCESS EXCLUSIVE | Use ADD CONSTRAINT ... NOT VALID, then VALIDATE CONSTRAINT |
DBM-007 | High | alter_orders.sql:1 | No SET lock_timeout guard (risks connection-pool lock pileup) | Prepend SET lock_timeout = '3s'; SET statement_timeout = '30s'; |
REL-001 | High | deployment.yaml:22 | App container runs alembic upgrade head on pod startup | Move to pre-deploy Kubernetes Job + set maxUnavailable: 0 |
Safe 3-Phase Expand-and-Contract Rewrite (Phase 1 — Expand)
SET lock_timeout = '3s';
SET statement_timeout = '30s';
-- 1. Non-blocking index build (run outside transaction block)
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_orders_customer_created
ON orders (customer_id, created_at DESC);
-- 2. Non-blocking constraint addition (metadata-only lock, then SHARE UPDATE EXCLUSIVE)
ALTER TABLE orders
ADD CONSTRAINT chk_orders_total_nonneg CHECK (total_cents >= 0) NOT VALID;
ALTER TABLE orders VALIDATE CONSTRAINT chk_orders_total_nonneg;
Next Steps (Approval Required)
- Phase 1 (Safe Now): Deploy expand migration + dual-read/write app code.
- Phase 2 (After Backfill): Validate constraints and remove reads of
legacy_status. - Phase 3 (Contract): Drop
legacy_statusafter all old pods drain.
Reply "Generate Phase 1 migration & rollback SQL" to write the files.
Connects securely to your tools. The creator never sees your data.
About this skill
Never Lock Production Tables or Break Rolling Deploys Again
Zero-Downtime DB Migration Safety Gate pairs a strictly read-only Python static analyzer (scripts/check_migrations.py) with senior database reliability playbooks (PostgreSQL lock matrix, MySQL 8 Online DDL matrix, and Expand-and-Contract recipes). It inspects your SQL, Prisma, Alembic, Flyway, Goose, and Kubernetes rollout manifests before merge and gives a clear GO / CONDITIONAL-GO / NO-GO release verdict.
What It Blocks (11 Production-Outage Rules)
- Database Lock & Breaking-Change Rules (
DBM-001–010):CREATE INDEX/DROP INDEXwithoutCONCURRENTLY(blocks writes/reads underSHARE/ACCESS EXCLUSIVElocks)- Single-step
DROP TABLE/DROP COLUMNandRENAME COLUMN/RENAME TABLE(crashes N-1 running pods during rolling deploys) - Full-table rewrite
ALTER COLUMN ... TYPEunderACCESS EXCLUSIVElock ADD COLUMN ... NOT NULLwithout safe default, andADD CONSTRAINT ... CHECK / FOREIGN KEYwithoutNOT VALID- Missing
lock_timeout/statement_timeoutguards (prevents lock-queue pileups that take down the whole app) - Unbounded
UPDATE/DELETEbackfills inside migration files,TRUNCATE, and empty/missing rollback (downgrade()) paths
- Rollout Coordination (
REL-001): Detects migrations run inside app container startup commands and Kubernetes Deployments missingmaxUnavailable: 0,readinessProbe, orterminationGracePeriodSeconds.
How to Use
Ask your AI agent before merging any schema change or production release:
- "Run a zero-downtime migration safety gate on
migrations/andk8s/before we deploy." - "Check if our Prisma / Alembic migration will lock our Postgres
orderstable or break running pods." - "Rewrite this risky migration into a safe multi-phase Expand-and-Contract plan with rollback SQL."
Or invoke the bundled read-only analyzer directly:
python3 scripts/check_migrations.py --path . --dialect auto --format markdown
What's Inside (17 Files)
SKILL.md— Deterministic 5-step release-safety workflow with GO / CONDITIONAL-GO / NO-GO gating and approval rulesscripts/check_migrations.py— Pure Python 3 stdlib static analyzer (11 rules,--dialect postgres|mysql|auto,--fail-on-nogoCI gate)references/— PostgreSQL lock matrix, MySQL 8 Online DDL matrix, Expand-and-Contract playbook, and rollback/rollout checklisttemplates/— Migration safety review card & copy-paste incident rollback runbookexamples/— Worked review converting a blocking 50M-roworderstable migration into a safe 3-phase Expand-and-Contract plantests/— Risky & safe SQL/Alembic/K8s fixtures + runnable unit tests
Security & Privacy Guarantee
- 100% read-only & offline — NEVER connects to live databases, NEVER executes DDL, zero network calls, zero
subprocess, zeroos.environ. - Automatically skips
.env*, key, and credential files.
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Data & Databases.
Static analysis of SQL, Alembic Python, and Kubernetes YAML files; does not inspect live database table sizes, query plans, or active runtime locks.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 2 days ago
- Software
Python 3.9+ (stdlib only)
Permissions
Bundled analyzer is 100% offline and read-only; never connects to any live database or runs DDL. Write Files is only used after explicit user approval to write safe migration phases or rollback runbooks.