Database Migration Creator
Generates a database migration file with up/down methods, type-safe schema changes, and a rollback plan.
SKILL.md
---
description: Create a database migration with up/down and rollback safety
allowed-tools: Read, Write, Bash(ls), Bash(cat *), Glob
---
# Database Migration Creator
Generate a safe, reversible database migration based on the requested schema change.
## Arguments
- `$ARGUMENTS` — description of the schema change (e.g. "add email_verified boolean column to users table")
## Steps
1. Identify the migration tool in use by checking for:
- `prisma/` directory → Prisma Migrate
- `drizzle/` or `drizzle.config.*` → Drizzle Kit
- `migrations/` with numbered SQL files → raw SQL migrations
- `knexfile.*` → Knex.js migrations
- `sequelize` in package.json → Sequelize CLI
2. Read the existing schema or recent migrations to understand:
- Current table structure and relationships
- Naming conventions (snake_case vs camelCase, plural vs singular)
- Whether timestamps (`created_at`, `updated_at`) are standard
3. Generate the migration file in the correct format for the detected tool.
## Migration requirements
### Up migration
- Add columns with sensible defaults for existing rows.
- Create indexes for columns that will be queried frequently.
- Add foreign key constraints with appropriate `ON DELETE` behavior.
- Use `NOT NULL` with defaults rather than nullable columns where possible.
### Down migration
- Reverse every change made in the up migration.
- Drop indexes before dropping columns.
- Handle data loss warnings (e.g. dropping a column with data).
### Safety checks
- Never drop a table or column in the up migration without explicit confirmation in `$ARGUMENTS`.
- For large tables, note that `ALTER TABLE` may lock the table — suggest batched approaches if applicable.
- Include a comment block at the top with:
- Description of the change
- Tables affected
- Whether the migration is reversible
- Estimated risk level (low/medium/high)
## Rules
- Follow the project's existing naming convention for migration files.
- Never modify existing migration files — always create new ones.
- Include the current timestamp or sequential number in the filename as per project convention.
- If adding an enum type, create it in a separate migration that runs first.How It Works
This skill demonstrates automatic tool detection — rather than asking the developer which migration framework they use, it inspects the project structure to figure it out. This means one skill works across Prisma, Drizzle, Knex, Sequelize, and raw SQL migrations.
The safety-first approach is crucial for database migrations, which can cause data loss if written carelessly. The skill requires reversible migrations by default, mandates sensible defaults for new columns (so existing rows are not broken), and refuses to drop tables without explicit confirmation.
The risk assessment comment block at the top of each migration is a production-readiness detail that many developers overlook. It helps DBAs and team leads quickly evaluate whether a migration can be run during business hours or needs a maintenance window.