$npx -y skills add saifoelloh/golang-best-practices-skill --skill migration-safetyDatabase migration safety review for GORM + PostgreSQL. Use when writing or reviewing schema changes, AutoMigrate usage, ALTER TABLE statements, or index creation. Covers zero-downtime patterns, NOT NULL backfill, CONCURRENTLY indexes, idempotency, and rollback files.
| 1 | # Migration Safety |
| 2 | |
| 3 | Expert-level review of database migration safety for production PostgreSQL deployments. Ensures zero-downtime schema changes, correct rollback capability, and idempotent migrations. |
| 4 | |
| 5 | ## When to Apply |
| 6 | |
| 7 | Use this skill when: |
| 8 | - Writing new migration files (`*.up.sql`, `*.down.sql`) |
| 9 | - Using GORM `AutoMigrate` |
| 10 | - Adding columns, indexes, or constraints to existing tables |
| 11 | - Dropping columns or tables |
| 12 | - Reviewing migrations before deploying to production |
| 13 | |
| 14 | ## Zero-Downtime Migration Checklist |
| 15 | |
| 16 | Before any production migration: |
| 17 | - [ ] NOT NULL column has DEFAULT or backfill migration first |
| 18 | - [ ] Indexes use `CONCURRENTLY` |
| 19 | - [ ] Migration is idempotent (`IF NOT EXISTS` / `IF EXISTS`) |
| 20 | - [ ] `down.sql` rollback file exists and is tested |
| 21 | - [ ] DROP COLUMN is in a separate deploy after code references removed |
| 22 | - [ ] AutoMigrate is not in the application startup path |
| 23 | |
| 24 | ## Rule Categories |
| 25 | |
| 26 | | Priority | Count | Focus | |
| 27 | |---|---|---| |
| 28 | | Critical | 3 | AutoMigrate in production, NOT NULL backfill, missing rollback | |
| 29 | | High | 2 | CONCURRENTLY indexes, idempotent migrations | |
| 30 | | Medium | 1 | DROP COLUMN deprecation period | |
| 31 | |
| 32 | ## Rules Covered (6 total) |
| 33 | |
| 34 | ### Critical Issues (3) |
| 35 | - `critical-no-automigrate-production` — Never run AutoMigrate in production startup path |
| 36 | - `critical-not-null-backfill` — NOT NULL column addition requires 3-step migration |
| 37 | - `critical-always-provide-rollback` — Every migration must have a paired `down.sql` |
| 38 | |
| 39 | ### High-Impact Patterns (2) |
| 40 | - `high-create-index-concurrently` — Use `CREATE INDEX CONCURRENTLY` to avoid write locks |
| 41 | - `high-idempotent-migration` — Use `IF NOT EXISTS` / `IF EXISTS` for safe re-runs |
| 42 | |
| 43 | ### Medium Improvements (1) |
| 44 | - `medium-drop-column-deprecation` — Deprecate before dropping — never drop in same deploy as code changes |
| 45 | |
| 46 | ## Trigger Phrases |
| 47 | |
| 48 | - "Review this migration" |
| 49 | - "Is this migration safe?" |
| 50 | - "ALTER TABLE" |
| 51 | - "ADD COLUMN / DROP COLUMN" |
| 52 | - "CREATE INDEX" |
| 53 | - "AutoMigrate" |
| 54 | - "Schema change" |
| 55 | - "Zero-downtime migration" |
| 56 | |
| 57 | ## Related Skills |
| 58 | |
| 59 | - [query-performance](../query-performance/SKILL.md) — For index design (partial, composite) |
| 60 | - [postgresql-syntax](../postgresql-syntax/SKILL.md) — For correct DDL SQL syntax |