Database Migration
Create safe, append-only schema changes with regeneration.
Canonical files
- •
migrations/*.up.sql/migrations/*.down.sql - •
schema.sql(generated) - •
internal/*/queries.sql+internal/store/*.go(generated via sqlc)
Procedure
- •Create a migration file pair:
- •
.agents/skills/db-migration/scripts/new-migration.sh <name>
- •
- •Write
up.sqlwith explicit indexes for new query patterns. - •Write
down.sqlthat safely reversesup.sql. - •Apply and regenerate:
- •
make migrate - •
make schema-dump - •
make generate-sqlc
- •
- •If queries changed, run
make generate. - •Update affected handlers/services/tests.
- •Update
progress.mdwith migration status and follow-ups.
Zero-downtime rules
- •Never edit committed migration files; add new migrations only.
- •Use two-step destructive changes:
- •Step 1: add nullable/new field and backfill
- •Step 2: remove old field later after code rollout
- •Add indexes for filter/sort paths.
- •Keep list queries bounded (
LIMIT/OFFSET) and indexed.
Commit rule
Commit migration files together with generated artifacts (schema.sql, sqlc output).