$npx -y skills add girijashankarj/cursor-handbook --skill create-migrationCreate a new database migration following project naming and safety rules. Use when the user asks to add a migration or create a migration for a schema change.
| 1 | # Skill: Create migration |
| 2 | |
| 3 | ## Trigger |
| 4 | When the user asks to add a migration, create a migration for a schema change, or "migrate the DB." |
| 5 | |
| 6 | ## Steps |
| 7 | |
| 8 | 1. **Clarify** — Confirm the change (new table, new column, index, constraint); ensure backward compatible where possible. |
| 9 | 2. **Naming** — Use format `YYYYMMDDHHMMSS_descriptive_action.sql` (or project equivalent). |
| 10 | 3. **UP** — Write the forward migration (ADD COLUMN with default, CREATE INDEX CONCURRENTLY where supported). |
| 11 | 4. **DOWN** — Write the rollback; test that DOWN reverts UP cleanly. |
| 12 | 5. **Review** — No raw DELETE; use soft delete if needed; parameterized only; add index for new FK/filters. |
| 13 | |
| 14 | ## If a step fails |
| 15 | |
| 16 | | Step | Failure | Recovery | |
| 17 | |------|---------|----------| |
| 18 | | Step 4 | DOWN does not revert UP cleanly | Fix DOWN to match UP; test both directions; document manual steps if schema change is irreversible | |
| 19 | | Step 5 | Review finds unsafe patterns | Rewrite migration; no raw DELETE; use soft delete; add defaults for new columns | |
| 20 | |
| 21 | ## Rules |
| 22 | - Follow `.cursor/rules/database/migration-rules.mdc` and schema-design rules. |
| 23 | - Every table must have id, created_at, updated_at, and soft-delete column per project config. |