Skill: Database Migration
Description
Handles safe database schema changes and data migrations.
When to Use
- •Adding/modifying database tables or columns
- •Changing relationships between entities
- •Data transformations
Instructions
Migration Rules
- •Always reversible — every migration needs an
upanddown - •One change per migration — don't bundle unrelated schema changes
- •Test on dev first — never run untested migrations in production
- •Backup before production — always have a rollback plan
- •No data loss — add columns as nullable first, then backfill
Drizzle Workflow
bash
# Generate migration from schema changes npx drizzle-kit generate # Review generated SQL in drizzle/ folder # Apply migration npx drizzle-kit push # Or use migrate for production npx drizzle-kit migrate
Naming Convention
YYYYMMDD_HHMMSS_description.sql
Example: 20260212_143000_add_user_roles.sql
Dangerous Operations Checklist
- • Column rename → Create new, copy data, drop old (3-step)
- • Column type change → Verify data compatibility first
- • Drop table → Confirm no foreign key references
- • Add NOT NULL → Set default or backfill first