
Database Migrations
Apply production-safe schema and data migrations with ORM-aware patterns, concurrent indexes, and zero-downtime discipline before you ship database changes.
Overview
Database Migrations is an agent skill most often used in Ship (also Build) that enforces safe, reversible schema and data migration patterns for production PostgreSQL, MySQL, and common ORMs.
Install
npx skills add https://github.com/affaan-m/everything-claude-code --skill database-migrationsWhat is this skill?
- Five core principles: every change is a migration, forward-only in prod, separate DDL from DML, test at production scale
- Migration safety checklist before apply: UP/DOWN, avoid full table locks, nullable or defaulted new columns, concurrent
- Covers PostgreSQL, MySQL, Prisma, Drizzle, Kysely, Django, TypeORM, and golang-migrate
- Explicit guidance for data migrations, rollbacks via new forward migrations, and tooling setup for new projects
- Activates when altering tables, indexes, backfills, or planning zero-downtime schema work
- 5 core migration principles
- Pre-apply migration safety checklist with multiple gated items
- Supports 8+ stacks: PostgreSQL, MySQL, Prisma, Drizzle, Kysely, Django, TypeORM, golang-migrate
Adoption & trust: 5.4k installs on skills.sh; 210k GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You are about to alter production tables but lack a checklist that prevents locks, mixed DDL/DML, and unrecoverable migration edits.
Who is it for?
Solo builders shipping SaaS or APIs on Postgres/MySQL who use Prisma, Drizzle, Django, or similar and cannot afford downtime.
Skip if: Greenfield prototypes with disposable SQLite-only schemas or teams that still hand-edit production databases without migration files.
When should I use this skill?
Creating or altering tables; adding/removing columns or indexes; data backfill migrations; zero-downtime schema planning; setting up migration tooling for a new project.
What do I get? / Deliverables
You ship reviewed UP/DOWN migrations with concurrent indexes, separated backfills, and forward-only rollback strategy aligned to your ORM.
- Reviewed UP/DOWN (or marked irreversible) migration files
- Separated schema and data migration steps with concurrent index patterns where needed
Recommended Skills
Journey fit
Spans multiple journey phases - primary shelf plus alternate fits below.
The canonical shelf is Ship because the skill optimizes for production deployment safety, immutability after deploy, and zero-downtime launch—not first-time local schema sketching. Launch fits zero-downtime schema changes and rolling deploys without taking production offline, which is the skill's stated production focus.
Where it fits
Add a nullable column and concurrent index in Drizzle before the feature branch merges.
Sequence deploy so expand-migrate-contract avoids downtime during a column type change.
Validate migrations never mix destructive DML with DDL in a single file before CI promote.
Ship a new forward migration to correct drift instead of editing an already-deployed revision.
How it compares
Production migration playbook with an explicit safety checklist—not a one-off SQL snippet generator.
Common Questions / FAQ
Who is database-migrations for?
Indie developers and small teams running real databases in production who want agent-guided migration files that follow zero-downtime and immutability rules.
When should I use database-migrations?
During build when creating or altering tables and indexes, during ship when planning zero-downtime deploys and launch prep, and during operate when running backfills or fixing schema drift with new forward migrations.
Is database-migrations safe to install?
Check the Security Audits panel on this page; the skill does not run migrations itself but guides destructive-capable DDL—always review generated SQL in staging and keep backups.
SKILL.md
READMESKILL.md - Database Migrations
# Database Migration Patterns Safe, reversible database schema changes for production systems. ## When to Activate - Creating or altering database tables - Adding/removing columns or indexes - Running data migrations (backfill, transform) - Planning zero-downtime schema changes - Setting up migration tooling for a new project ## Core Principles 1. **Every change is a migration** — never alter production databases manually 2. **Migrations are forward-only in production** — rollbacks use new forward migrations 3. **Schema and data migrations are separate** — never mix DDL and DML in one migration 4. **Test migrations against production-sized data** — a migration that works on 100 rows may lock on 10M 5. **Migrations are immutable once deployed** — never edit a migration that has run in production ## Migration Safety Checklist Before applying any migration: - [ ] Migration has both UP and DOWN (or is explicitly marked irreversible) - [ ] No full table locks on large tables (use concurrent operations) - [ ] New columns have defaults or are nullable (never add NOT NULL without default) - [ ] Indexes created concurrently (not inline with CREATE TABLE for existing tables) - [ ] Data backfill is a separate migration from schema change - [ ] Tested against a copy of production data - [ ] Rollback plan documented ## PostgreSQL Patterns ### Adding a Column Safely ```sql -- GOOD: Nullable column, no lock ALTER TABLE users ADD COLUMN avatar_url TEXT; -- GOOD: Column with default (Postgres 11+ is instant, no rewrite) ALTER TABLE users ADD COLUMN is_active BOOLEAN NOT NULL DEFAULT true; -- BAD: NOT NULL without default on existing table (requires full rewrite) ALTER TABLE users ADD COLUMN role TEXT NOT NULL; -- This locks the table and rewrites every row ``` ### Adding an Index Without Downtime ```sql -- BAD: Blocks writes on large tables CREATE INDEX idx_users_email ON users (email); -- GOOD: Non-blocking, allows concurrent writes CREATE INDEX CONCURRENTLY idx_users_email ON users (email); -- Note: CONCURRENTLY cannot run inside a transaction block -- Most migration tools need special handling for this ``` ### Renaming a Column (Zero-Downtime) Never rename directly in production. Use the expand-contract pattern: ```sql -- Step 1: Add new column (migration 001) ALTER TABLE users ADD COLUMN display_name TEXT; -- Step 2: Backfill data (migration 002, data migration) UPDATE users SET display_name = username WHERE display_name IS NULL; -- Step 3: Update application code to read/write both columns -- Deploy application changes -- Step 4: Stop writing to old column, drop it (migration 003) ALTER TABLE users DROP COLUMN username; ``` ### Removing a Column Safely ```sql -- Step 1: Remove all application references to the column -- Step 2: Deploy application without the column reference -- Step 3: Drop column in next migration ALTER TABLE orders DROP COLUMN legacy_status; -- For Django: use SeparateDatabaseAndState to remove from model -- without generating DROP COLUMN (then drop in next migration) ``` ### Large Data Migrations ```sql -- BAD: Updates all rows in one transaction (locks table) UPDATE users SET normalized_email = LOWER(email); -- GOOD: Batch update with progress DO $$ DECLARE batch_size INT := 10000; rows_updated INT; BEGIN LOOP UPDATE users SET normalized_email = LOWER(email) WHERE id IN ( SELECT id FROM users WHERE normalized_email IS NULL LIMIT batch_size FOR UPDATE SKIP LOCKED ); GET DIAGNOSTICS rows_updated = ROW_COUNT; RAISE NOTICE 'Updated % rows', rows_updated; EXIT WHEN rows_updated = 0; COMMIT; END LOOP; END $$; ``` ## Prisma (TypeScript/Node.js) ### Workflow ```b