Skip to content
/migrateStable

Guides database schema migrations, API version upgrades, and framework migrations with rollback safety.

DatabaseDevOpsΒ· 2 min read

Quick import: Download the .md file and save it to .claude/commands/ (Claude Code), .cursorrules (Cursor), or paste as a system prompt in ChatGPT, Gemini, or any LLM API.

#What it does

The /migrate skill handles the full lifecycle of code and data migrations -- from database schema changes and API version bumps to framework upgrades and library replacements. It generates migration files, plans the rollback strategy, and ensures zero-downtime transitions by breaking large migrations into safe, reversible steps.

#How to use

bash
/migrate Add a "role" column to the users table with default "member"
bash
/migrate Upgrade from Next.js 14 to Next.js 15
bash
/migrate Replace moment.js with date-fns across the project

#Workflow

  1. Assess -- Analyze the current state: existing schema, API consumers, framework version, dependency graph. Identify the blast radius of the change
  2. Plan -- Break the migration into atomic, reversible steps. Each step should be independently deployable and rollback-safe
  3. Generate -- Create migration files (SQL, ORM migration, codemods) with both up and down operations
  4. Validate -- Check for breaking changes: foreign key constraints, type mismatches, removed fields still in use, API consumers that depend on old behavior
  5. Execute -- Apply the migration with verification at each step. For database changes, test against a copy of production data first
  6. Rollback Plan -- Document the exact commands to reverse every step if something goes wrong

#Example

bash
> /migrate Split the "name" column into "first_name" and "last_name"
 
## Migration Plan (3 phases, zero downtime)
 
### Phase 1: Add new columns (backward compatible)
- Add first_name VARCHAR(100) nullable
- Add last_name VARCHAR(100) nullable
- Deploy: app writes to both old and new columns
 
### Phase 2: Backfill data
- UPDATE users SET first_name = split(name)[0], last_name = split(name)[1]
- Verify: SELECT count(*) WHERE first_name IS NULL
- Deploy: app reads from new columns
 
### Phase 3: Drop old column (after verification period)
- ALTER TABLE users DROP COLUMN name
- Rollback window: 7 days before this step

#Safety features

  • Never generates destructive migrations without a rollback step
  • Warns about migrations that lock large tables
  • Checks for dependent views, triggers, and foreign keys before dropping columns
  • Recommends expand-contract pattern for breaking schema changes
Orel OhayonΒ·
View all skills