safe-database-migrations
/safe-database-migrations
Use when writing or reviewing a database schema migration, especially on a live system. Covers the expand/contract pattern for zero-downtime changes, avoiding long locks, safe backfills, and always having a rollback path.
- Author
- alisinadevelo ↗
- Repository
- md-files ↗
- Licence
- MIT
- Last repository change
- 03.10.2026
Assessment and security
- Files in this package
- 1
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 0
No signals detected. Repository changed on 03.10.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
Use when writing or reviewing a database schema migration, especially on a live system. Covers the expand/contract pattern for zero-downtime changes, avoiding long locks, safe backfills, and always having a rollback path.
Original author description
Use when writing or reviewing a database schema migration, especially on a live system. Covers the expand/contract pattern for zero-downtime changes, avoiding long locks, safe backfills, and always having a rollback path.
How it works
- The expand/contract pattern
- Avoid long locks
- Always have a rollback
- Before running on production
- Red flags in review
SKILL.md preview
--- name: safe-database-migrations description: >- Use when writing or reviewing a database schema migration, especially on a live system. Covers the expand/contract pattern for zero-downtime changes, avoiding long locks, safe backfills, and always having a rollback path. --- # Safe Database Migrations A migration runs against live data with live traffic. The goals: no downtime, no data loss, and a way back if it goes wrong. Schema changes are the highest-risk routine operation most teams perform — treat them with care. ## The expand/contract pattern Never make a breaking schema change in one step. Split it across deploys so old and new code both work at every point: 1. **Expand** — add the new structure, backward-compatible. New nullable column, new table, new index (built concurrently). Old code ignores it. 2. **Migrate** — backfill data in **batches** (not one giant `UPDATE`), and deploy code that writes to both old and new (dual-write) while still reading old. 3. **Switch** — deploy code that reads from the new structure. 4. **Contract** — once nothing references the old structure, add constraints (NOT NULL after backfill) and drop the old column/table in a later deploy. Each step is independently deployable and reversible. ## Avoid long locks - Adding a NOT NULL column with a default can rewrite the whole table on some engines — add nullable, backfill, then set the constraint. - Build indexes concurrently / online where the engine supports it. - Backfill in bounded batches with a short pause; a single large transaction holds locks and bloats replication lag. - Know your engine's locking semantics for each DDL operation before you run it. ## Always have a rollback Every forward migration needs a tested `down`, or an explicit, documented reason it's irreversible (and then: backup first). A dropped column or table is not reversible — treat destructive steps as one-way doors and gate them behind a verified, idle period. ## Before running on production - Test on a copy with **realistic data volume** — a migration that's instant on 100 rows can lock a table for minutes on 100M. - Estimate lock duration and replication impact. - Make data migrations idempotent and resumable so a mid-run failure can be retried. - Separate schema changes from data changes from code deploys where possible. ## Red flags in review A single `UPDATE` over a huge table · `ALTER TABLE` that rewrites in place under load · NOT NULL added before backfill · a `down` migration that loses data silently · no batch size on a backfill · dropping a column in the same deploy that stops using it.
Versions
| Repository | Score | Licence |
|---|---|---|
| This page · alisinadevelo/md-files | 90 | MIT |
| Gattic/GatPi-Harness | 90 | MIT |
Database snapshot: 13.11.2026 · package version 2f3a668d0993 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 1 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 90migration-strategies
Migration strategies: zero-downtime deployments, expand-contract schema changes, database migrations, framework migrations. Use when planning system migrations. - 100database-migrations
Plans and writes zero-downtime database schema migrations (expand/contract, safe indexes, batched backfills, rollback). Use when adding, renaming or dropping columns or tables, changing types or constraints, adding indexes, or backfilling data on a live database. - 90migrations
Change a live schema without breaking the application on it — expand/contract sequencing, lock-safe DDL, batched backfills, and a rollback that is actually reachable. Use when writing, reviewing or sequencing a migration that will run against a database holding real data with… - 100schema-evolution-planner
Plan zero-downtime schema changes across code, data backfills, and cutovers. Use for expand-contract database changes. NOT for fresh schema design or DBA ops. - 100expand-contract
Plan and execute zero-downtime database schema migrations, breaking API changes, or wide refactors using the Expand-Contract pattern. Use when modifying database schemas, altering API contracts, or refactoring high-blast-radius code. - 100safe-migrations
Use when writing, generating, reviewing, or running database schema migrations or data backfills (raw SQL, Prisma, Drizzle, Rails, Django, Alembic, Laravel, Knex, Ecto, Flyway, etc.), and before any command that resets, drops, truncates, or wipes a database. Rewrites operations…