migration
Create reversible database migrations with rollback scripts. Use when modifying database schemas.
When & Why to Use This Skill
This Claude skill streamlines the database schema management process by generating safe, reversible migrations. It provides standardized SQL templates for both 'UP' and 'DOWN' scripts, ensuring that every database change is accompanied by a reliable rollback plan. By integrating risk assessment levels and specialized strategies for high-volume data, it helps developers maintain data integrity and minimize downtime during deployments.
Use Cases
- Standardized Schema Changes: Automatically generating SQL migration scripts for adding tables, columns, or indexes with built-in rollback logic.
- Risk Assessment & Safety: Evaluating the impact of schema modifications by categorizing them into safe, risky, or dangerous operations to prevent accidental data loss.
- Large-Scale Data Migrations: Implementing batch-processing and structure-switching strategies for tables with over 1 million rows to ensure performance stability.
- Production Deployment Readiness: Utilizing pre-migration checklists to verify backups, test rollback scripts, and assess performance impacts before executing changes in live environments.
| name | migration |
|---|---|
| description | Create reversible database migrations with rollback scripts. |
Migration Skill
Purpose
Create safe, reversible database migrations.
Migration Template
Use: templates/migration-template.sql
-- Migration: [description]
-- Created: [date]
-- Author: [name]
-- ==================== UP ====================
BEGIN;
-- Your migration here
CREATE TABLE users (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
email VARCHAR(255) NOT NULL UNIQUE,
created_at TIMESTAMP DEFAULT NOW()
);
COMMIT;
-- ==================== DOWN ====================
BEGIN;
DROP TABLE IF EXISTS users;
COMMIT;
Pre-Migration Checklist
Use: checklists/pre-migration.md
- Down migration works
- Tested on production-like data
- Performance impact assessed
- Backup plan documented
- Deployment timing considered
Migration Types
Safe Migrations
- Add table
- Add nullable column
- Add index (CONCURRENTLY)
- Add foreign key (without validation)
Risky Migrations
- Drop table (verify no references)
- Drop column (verify no usage)
- Rename column (may break app)
- Change column type (may lose data)
Dangerous Migrations
- Truncate table
- Drop database
- Remove constraints
Large Table Migrations
For tables with >1M rows:
- Create new structure
- Backfill in batches
- Add constraints
- Switch over
- Clean up old structure
Rollback Strategy
- Test down migration before running up
- Document manual rollback steps
- Have production backup
- Consider feature flags for code changes