Database Migration Manager
Expert in safe, reversible database schema migrations with zero-downtime deployment strategies.
Activation Triggers
Activate on: "database migration", "schema change", "alter table", "add column", "drop column", "zero-downtime DDL", "rollback plan", "Prisma migrate", "Drizzle kit", "Flyway", "migration strategy"
NOT for: Query optimization → database-optimizer | ORM data modeling → data-pipeline-engineer | Backup/restore → devops-automator
Quick Start
- Assess the change — additive (safe), modification (needs strategy), or destructive (needs expand-contract)
- Write the migration — forward migration with explicit rollback SQL
- Test on staging — run against a copy of production data volume
- Plan zero-downtime — use expand-contract for breaking changes
- Execute with monitoring — deploy migration, watch error rates, rollback if needed
Core Capabilities
| Domain |
Technologies |
| ORM Migrations |
Prisma Migrate, Drizzle Kit, TypeORM, Sequelize |
| SQL Migrations |
Flyway, Liquibase, golang-migrate, dbmate, Atlas |
| Zero-Downtime |
Expand-contract, shadow columns, online DDL (pt-online-schema-change) |
| Databases |
PostgreSQL 17, MySQL 8.4, SQLite, CockroachDB, PlanetScale |
| Safety |
Rollback scripts, dry-run validation, lock timeout guards |
Architecture Patterns
Expand-Contract Pattern (Zero-Downtime Column Rename)
Phase 1 — EXPAND (deploy migration, app reads both):
├─ Add new column `full_name`
├─ Backfill: UPDATE users SET full_name = name
├─ Add trigger: sync writes to both columns
└─ Deploy app reading `full_name`, falling back to `name`
Phase 2 — MIGRATE (app writes to new only):
├─ Deploy app writing only to `full_name`
└─ Verify no reads/writes to old column (query logs)
Phase 3 — CONTRACT (remove old):
├─ Drop trigger
├─ Drop old column `name`
└─ Clean migration: one final migration file
Safe Migration Template (PostgreSQL)
-- migrations/20260320_001_add_email_verified.sql
-- FORWARD
BEGIN;
SET lock_timeout = '5s'; -- Fail fast if table locked
ALTER TABLE users
ADD COLUMN IF NOT EXISTS email_verified boolean
DEFAULT false NOT NULL;
CREATE INDEX CONCURRENTLY IF NOT EXISTS
idx_users_email_verified ON users(email_verified)
WHERE email_verified = true;
COMMIT;
-- ROLLBACK (in companion file or comment block)
-- BEGIN;
-- DROP INDEX CONCURRENTLY IF EXISTS idx_users_email_verified;
-- ALTER TABLE users DROP COLUMN IF EXISTS email_verified;
-- COMMIT;
Migration Safety Ladder
Risk Level 1 (Safe): ADD COLUMN (nullable), CREATE INDEX CONCURRENTLY
Risk Level 2 (Caution): ADD COLUMN (with default), ADD NOT NULL constraint
Risk Level 3 (Danger): ALTER COLUMN TYPE, RENAME COLUMN
Risk Level 4 (Critical): DROP COLUMN, DROP TABLE
↓
Requires expand-contract pattern
Anti-Patterns
- Running migrations in application startup — if the migration fails, the app cannot start and cannot roll back. Run migrations as a separate CI/CD step with its own rollback.
- No lock_timeout —
ALTER TABLE acquires an ACCESS EXCLUSIVE lock. Without timeout, it queues behind long queries and blocks all subsequent queries. Always set lock_timeout.
- Destructive changes without expand-contract — dropping or renaming columns while the old app version still reads them causes errors. Always use the expand-contract pattern for breaking changes.
- Missing rollback scripts — every forward migration needs a tested rollback. If you cannot roll back, the migration is not safe for production.
- Backfilling in the migration transaction — large backfills in a single transaction lock the table for minutes. Backfill in batches outside the DDL transaction.
Quality Checklist
[ ] Migration has explicit rollback SQL
[ ] lock_timeout set for all DDL statements
[ ] CREATE INDEX uses CONCURRENTLY
[ ] Breaking changes use expand-contract pattern
[ ] Backfills run in batches (1000-10000 rows per batch)
[ ] Migration tested against production-volume staging data
[ ] No data loss — dropped columns backed up or archived
[ ] Migration is idempotent (IF NOT EXISTS / IF EXISTS guards)
[ ] Application code deployed before destructive phase
[ ] Monitoring dashboards checked during and after migration
[ ] Migration numbered/timestamped for ordering
[ ] Rollback tested independently on staging
1---
2license: Apache-2.0
3name: database-migration-manager
4description: 'Safe database migration manager for zero-downtime DDL changes and rollback plans. Activate on: database migration, schema change, DDL, rollback plan, zero-downtime migration, Prisma migrate, Drizzle kit, Flyway, column rename, table alter. NOT for: query optimization (use database-optimizer), ORM modeling (use data-pipeline-engineer), backup/restore (use devops-automator).'
5allowed-tools: Read,Write,Edit,Bash(docker:*,kubectl:*,terraform:*,npm:*,npx:*)
6category: Backend & Infrastructure
7tags:
8 - database
9 - migrations
10 - schema
11 - devops
12pairs-with:
13 - skill: drizzle-migrations
14 reason: Drizzle-specific migration patterns this skill generalizes
15 - skill: data-pipeline-engineer
16 reason: Schema design that migrations implement
17metadata:
18 source: https://skillmd.com/skills/curiositech/database-migration-manager
19---
20
21# Database Migration Manager
22
23Expert in safe, reversible database schema migrations with zero-downtime deployment strategies.
24
25## Activation Triggers
26
27**Activate on:** "database migration", "schema change", "alter table", "add column", "drop column", "zero-downtime DDL", "rollback plan", "Prisma migrate", "Drizzle kit", "Flyway", "migration strategy"
28
29**NOT for:** Query optimization → `database-optimizer` | ORM data modeling → `data-pipeline-engineer` | Backup/restore → `devops-automator`
30
31## Quick Start
32
331. **Assess the change** — additive (safe), modification (needs strategy), or destructive (needs expand-contract)
342. **Write the migration** — forward migration with explicit rollback SQL
353. **Test on staging** — run against a copy of production data volume
364. **Plan zero-downtime** — use expand-contract for breaking changes
375. **Execute with monitoring** — deploy migration, watch error rates, rollback if needed
38
39## Core Capabilities
40
41| Domain | Technologies |
42|--------|-------------|
43| **ORM Migrations** | Prisma Migrate, Drizzle Kit, TypeORM, Sequelize |
44| **SQL Migrations** | Flyway, Liquibase, golang-migrate, dbmate, Atlas |
45| **Zero-Downtime** | Expand-contract, shadow columns, online DDL (pt-online-schema-change) |
46| **Databases** | PostgreSQL 17, MySQL 8.4, SQLite, CockroachDB, PlanetScale |
47| **Safety** | Rollback scripts, dry-run validation, lock timeout guards |
48
49## Architecture Patterns
50
51### Expand-Contract Pattern (Zero-Downtime Column Rename)
52
53```
54Phase 1 — EXPAND (deploy migration, app reads both):
55 ├─ Add new column `full_name`
56 ├─ Backfill: UPDATE users SET full_name = name
57 ├─ Add trigger: sync writes to both columns
58 └─ Deploy app reading `full_name`, falling back to `name`
59
60Phase 2 — MIGRATE (app writes to new only):
61 ├─ Deploy app writing only to `full_name`
62 └─ Verify no reads/writes to old column (query logs)
63
64Phase 3 — CONTRACT (remove old):
65 ├─ Drop trigger
66 ├─ Drop old column `name`
67 └─ Clean migration: one final migration file
68```
69
70### Safe Migration Template (PostgreSQL)
71
72```sql
73-- migrations/20260320_001_add_email_verified.sql
74-- FORWARD
75BEGIN;
76SET lock_timeout = '5s'; -- Fail fast if table locked
77
78ALTER TABLE users
79 ADD COLUMN IF NOT EXISTS email_verified boolean
80 DEFAULT false NOT NULL;
81
82CREATE INDEX CONCURRENTLY IF NOT EXISTS
83 idx_users_email_verified ON users(email_verified)
84 WHERE email_verified = true;
85
86COMMIT;
87
88-- ROLLBACK (in companion file or comment block)
89-- BEGIN;
90-- DROP INDEX CONCURRENTLY IF EXISTS idx_users_email_verified;
91-- ALTER TABLE users DROP COLUMN IF EXISTS email_verified;
92-- COMMIT;
93```
94
95### Migration Safety Ladder
96
97```
98Risk Level 1 (Safe): ADD COLUMN (nullable), CREATE INDEX CONCURRENTLY
99Risk Level 2 (Caution): ADD COLUMN (with default), ADD NOT NULL constraint
100Risk Level 3 (Danger): ALTER COLUMN TYPE, RENAME COLUMN
101Risk Level 4 (Critical): DROP COLUMN, DROP TABLE
102 ↓
103 Requires expand-contract pattern
104```
105
106## Anti-Patterns
107
1081. **Running migrations in application startup** — if the migration fails, the app cannot start and cannot roll back. Run migrations as a separate CI/CD step with its own rollback.
1092. **No lock_timeout** — `ALTER TABLE` acquires an ACCESS EXCLUSIVE lock. Without timeout, it queues behind long queries and blocks all subsequent queries. Always set `lock_timeout`.
1103. **Destructive changes without expand-contract** — dropping or renaming columns while the old app version still reads them causes errors. Always use the expand-contract pattern for breaking changes.
1114. **Missing rollback scripts** — every forward migration needs a tested rollback. If you cannot roll back, the migration is not safe for production.
1125. **Backfilling in the migration transaction** — large backfills in a single transaction lock the table for minutes. Backfill in batches outside the DDL transaction.
113
114## Quality Checklist
115
116```
117[ ] Migration has explicit rollback SQL
118[ ] lock_timeout set for all DDL statements
119[ ] CREATE INDEX uses CONCURRENTLY
120[ ] Breaking changes use expand-contract pattern
121[ ] Backfills run in batches (1000-10000 rows per batch)
122[ ] Migration tested against production-volume staging data
123[ ] No data loss — dropped columns backed up or archived
124[ ] Migration is idempotent (IF NOT EXISTS / IF EXISTS guards)
125[ ] Application code deployed before destructive phase
126[ ] Monitoring dashboards checked during and after migration
127[ ] Migration numbered/timestamped for ordering
128[ ] Rollback tested independently on staging
129```