
Database Migrations
- 6.6k installs
- 238k repo stars
- Updated August 5, 2026
- affaan-m/everything-claude-code
A structured set of patterns, checklists, and ORM-specific commands for executing database schema changes safely in production, covering PostgreSQL, Prisma, Drizzle, Django, and golang-migrate.
About
This skill provides structured patterns and checklists for executing safe, reversible database schema changes in production systems. Developers use it when adding or removing columns, creating indexes, renaming fields, or running data backfills without causing downtime or table locks. The skill covers PostgreSQL-specific techniques such as CREATE INDEX CONCURRENTLY and batch UPDATE loops, plus ORM-specific workflows for Prisma, Drizzle, Django, and golang-migrate. A core workflow is the expand-contract pattern, which separates schema changes, data backfills, and column removal across multiple deployments. Anti-pattern tables document common mistakes - such as adding NOT NULL columns without defaults or mixing DDL and DML - alongside safer alternatives grounded in production-scale concerns like 10M-row tables and lock contention.
- Expand-contract pattern splits schema changes across three deployment phases to eliminate downtime on column renames and
- CREATE INDEX CONCURRENTLY guidance prevents write locks on large PostgreSQL tables during index builds
- Batch UPDATE loop with FOR UPDATE SKIP LOCKED handles large data migrations without locking entire tables
- ORM command references for Prisma, Drizzle, Django, and golang-migrate cover generate, apply, and rollback workflows
- Pre-migration safety checklist covers nullability, concurrent indexes, separate data migrations, and documented rollback
Database Migrations by the numbers
- 6,581 all-time installs (skills.sh)
- +265 installs in the week ending Aug 4, 2026 (Skillselion tracking)
- Ranked #124 of 4,347 Backend & APIs skills by installs in the Skillselion catalog
- Security screen: MEDIUM risk (skills.sh audit)
- Data as of Aug 5, 2026 (Skillselion catalog sync)
database-migrations capabilities & compatibility
free
- Capabilities
- zero downtime schema changes · concurrent index creation · batch data migration · orm migration workflow · expand contract pattern · rollback planning · anti pattern detection
- Works with
- postgres · mysql · supabase
- Use cases
- database · api development · devops
- Platforms
- macOS · Windows · Linux · WSL
- Runs
- Runs locally
- Pricing
- Free
What database-migrations says it does
a migration that works on 100 rows may lock on 10M
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_users_email ON users (email);
Phase 1: EXPAND - Add new column/table (nullable or with default) - Deploy: app writes to BOTH old and new
npx skills add https://github.com/affaan-m/everything-claude-code --skill database-migrationsAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 6.6k |
|---|---|
| repo stars | ★ 238k |
| Security audit | 3 / 3 scanners passed |
| Last updated | August 5, 2026 |
| Repository | affaan-m/everything-claude-code ↗ |
What it does
Guide safe, zero-downtime database schema changes using PostgreSQL patterns and ORMs including Prisma, Drizzle, Django, TypeORM, and golang-migrate.
Who is it for?
Backend developers managing relational databases in production who need to add columns, create indexes, or rename fields without downtime.
Skip if: Developers working exclusively with schema-less or document databases such as MongoDB where SQL migration patterns do not apply.
When should I use this skill?
Planning or implementing any database schema change, setting up migration tooling on a new project, or reviewing migration pull requests.
What you get
Developers can plan and execute zero-downtime schema changes with documented rollback plans, batch-safe data migrations, and ORM-appropriate tooling commands.
- Migration safety checklist for each schema change
- SQL scripts for safe column addition, index creation, and batch data updates
- ORM-specific CLI commands for generate, apply, and rollback workflows
By the numbers
- Batch size of 10,000 rows used in PostgreSQL batch UPDATE example
- Batch size of 5,000 rows used in Django bulk_update data migration example
- 3-phase expand-contract pattern spans example timeline of 7 days
Files
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
-- 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 rowAdding an Index Without Downtime
-- 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 thisRenaming a Column (Zero-Downtime)
Never rename directly in production. Use the expand-contract pattern:
-- 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
-- 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
-- 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
# Create migration from schema changes
npx prisma migrate dev --name add_user_avatar
# Apply pending migrations in production
npx prisma migrate deploy
# Reset database (dev only)
npx prisma migrate reset
# Generate client after schema changes
npx prisma generateSchema Example
model User {
id String @id @default(cuid())
email String @unique
name String?
avatarUrl String? @map("avatar_url")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
orders Order[]
@@map("users")
@@index([email])
}Custom SQL Migration
For operations Prisma cannot express (concurrent indexes, data backfills):
# Create empty migration, then edit the SQL manually
npx prisma migrate dev --create-only --name add_email_index-- migrations/20240115_add_email_index/migration.sql
-- Prisma cannot generate CONCURRENTLY, so we write it manually
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_users_email ON users (email);Drizzle (TypeScript/Node.js)
Workflow
# Generate migration from schema changes
npx drizzle-kit generate
# Apply migrations
npx drizzle-kit migrate
# Push schema directly (dev only, no migration file)
npx drizzle-kit pushSchema Example
import { pgTable, text, timestamp, uuid, boolean } from "drizzle-orm/pg-core";
export const users = pgTable("users", {
id: uuid("id").primaryKey().defaultRandom(),
email: text("email").notNull().unique(),
name: text("name"),
isActive: boolean("is_active").notNull().default(true),
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at").notNull().defaultNow(),
});Django (Python)
Workflow
# Generate migration from model changes
python manage.py makemigrations
# Apply migrations
python manage.py migrate
# Show migration status
python manage.py showmigrations
# Generate empty migration for custom SQL
python manage.py makemigrations --empty app_name -n descriptionData Migration
from django.db import migrations
def backfill_display_names(apps, schema_editor):
User = apps.get_model("accounts", "User")
batch_size = 5000
users = User.objects.filter(display_name="")
while users.exists():
batch = list(users[:batch_size])
for user in batch:
user.display_name = user.username
User.objects.bulk_update(batch, ["display_name"], batch_size=batch_size)
def reverse_backfill(apps, schema_editor):
pass # Data migration, no reverse needed
class Migration(migrations.Migration):
dependencies = [("accounts", "0015_add_display_name")]
operations = [
migrations.RunPython(backfill_display_names, reverse_backfill),
]SeparateDatabaseAndState
Remove a column from the Django model without dropping it from the database immediately:
class Migration(migrations.Migration):
operations = [
migrations.SeparateDatabaseAndState(
state_operations=[
migrations.RemoveField(model_name="user", name="legacy_field"),
],
database_operations=[], # Don't touch the DB yet
),
]golang-migrate (Go)
Workflow
# Create migration pair
migrate create -ext sql -dir migrations -seq add_user_avatar
# Apply all pending migrations
migrate -path migrations -database "$DATABASE_URL" up
# Rollback last migration
migrate -path migrations -database "$DATABASE_URL" down 1
# Force version (fix dirty state)
migrate -path migrations -database "$DATABASE_URL" force VERSIONMigration Files
-- migrations/000003_add_user_avatar.up.sql
ALTER TABLE users ADD COLUMN avatar_url TEXT;
CREATE INDEX CONCURRENTLY idx_users_avatar ON users (avatar_url) WHERE avatar_url IS NOT NULL;
-- migrations/000003_add_user_avatar.down.sql
DROP INDEX IF EXISTS idx_users_avatar;
ALTER TABLE users DROP COLUMN IF EXISTS avatar_url;Zero-Downtime Migration Strategy
For critical production changes, follow the expand-contract pattern:
Phase 1: EXPAND
- Add new column/table (nullable or with default)
- Deploy: app writes to BOTH old and new
- Backfill existing data
Phase 2: MIGRATE
- Deploy: app reads from NEW, writes to BOTH
- Verify data consistency
Phase 3: CONTRACT
- Deploy: app only uses NEW
- Drop old column/table in separate migrationTimeline Example
Day 1: Migration adds new_status column (nullable)
Day 1: Deploy app v2 — writes to both status and new_status
Day 2: Run backfill migration for existing rows
Day 3: Deploy app v3 — reads from new_status only
Day 7: Migration drops old status columnAnti-Patterns
| Anti-Pattern | Why It Fails | Better Approach |
|---|---|---|
| Manual SQL in production | No audit trail, unrepeatable | Always use migration files |
| Editing deployed migrations | Causes drift between environments | Create new migration instead |
| NOT NULL without default | Locks table, rewrites all rows | Add nullable, backfill, then add constraint |
| Inline index on large table | Blocks writes during build | CREATE INDEX CONCURRENTLY |
| Schema + data in one migration | Hard to rollback, long transactions | Separate migrations |
| Dropping column before removing code | Application errors on missing column | Remove code first, drop column next deploy |
When to Use This Skill
- Planning database schema changes
- Implementing zero-downtime migrations
- Setting up migration tooling
- Troubleshooting migration issues
- Reviewing migration pull requests
Related skills
Forks & variants (1)
Database Migrations has 1 known copy in the catalog totaling 1.5k installs. They canonicalize to this original listing.
- affaan-m - 1.5k installs
How it compares
Pick database-migrations over generic SQL skills when you need ORM-specific migration files, rollback plans, and zero-downtime deployment sequencing.
FAQ
How do I add a NOT NULL column to a large table without a full table rewrite?
Add the column as nullable first, backfill existing rows in a separate migration, then add the NOT NULL constraint in a third migration after all rows are populated.
How do I create an index on a large table without blocking writes?
Use CREATE INDEX CONCURRENTLY in PostgreSQL. Note that CONCURRENTLY cannot run inside a transaction block, so most migration tools require a custom SQL migration for this.
What is the expand-contract pattern?
A three-phase strategy: expand adds the new column, migrate backfills data and switches reads to the new column, and contract drops the old column in a later deployment.
Is Database Migrations safe to install?
skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.