HomeUse CasesZero-Downtime Schema Migration
New

Zero-Downtime Schema Migration

Change your database schema on a live system without downtime or data loss. This workflow makes the migration safe, adds the right indexes, catches N+1 queries the change might introduce, and locks in current behavior with a test safety net before you deploy.

2 Plugins
4 Steps
01

Rewrite the migration safely

SSsql-safety-net

Analyze the migration for the operations that take a full-table lock - ADD COLUMN NOT NULL DEFAULT, ALTER TYPE, a non-CONCURRENT index - and rewrite it into a safe, ordered expand-contract sequence with a paired rollback.

$/migration-safetydb/migrate/20260707_add_status.rb
Lock analysisExpand-contract planReversible steps
02

Add the right index

SSsql-safety-net

Given the slow query and the table DDL, get an index recommendation that gets the column order right (equality before range), uses covering columns where they help, and creates the index CONCURRENTLY so it does not block writes.

$/index-advisor--query "SELECT ... WHERE status = ? ORDER BY created_at"
Index recommendationColumn order rationaleCONCURRENTLY DDL
03

Hunt for N+1 queries

SSsql-safety-net

Scan the ORM code touched by the change for N+1 access patterns - loops over lazy-loaded relations, missing eager loading, serializer-triggered queries - and get the idiomatic batching fix for your ORM.

$/n1-scanapp/models/
N+1 findingsFile:line evidenceEager-load fixes
04

Lock in behavior with tests

TGtest-generator

Before deploying, generate characterization tests that pin the current behavior of the affected code paths. If the migration or query changes alter a result anywhere, the tests tell you immediately.

$/generate-unit-tests--type characterization --target app/models/
Characterization testsBehavior coverageRegression safety

Getting the most out of this workflow

Everything is static - no database connection needed. The checks run on the migration and ORM files you are already editing, so you can run them in a feature branch before touching any environment.

When you paste an EXPLAIN plan into /explain-plan, include EXPLAIN (ANALYZE, BUFFERS) output if you have it. Actual-vs-estimated row counts are where the real problems hide.

Run /n1-scan after adding any new relation access. A single .map() over lazy-loaded records can turn one query into a thousand in production.

Plugins in this workflow

SS
sql-safety-net
Steps 1-3 - Migration, indexes & N+1
TG
test-generator
Step 4 - Behavior safety net
Install all at once
/plugin install sql-safety-net
/plugin install test-generator

Prerequisites

Claude Code installed and running
ClaudeRegistry marketplace added
~
A migration file and the ORM or query code around it
i
Supports Postgres and MySQL, plus Django, Rails, Prisma, SQLAlchemy, and more

Tags

databasemigrationperformancezero-downtimesql

Have a workflow to share?

Submit your own use case and help other developers discover powerful plugin combinations.

Submit a Workflow →