mirror of
https://github.com/whekin/household-bot.git
synced 2026-03-31 21:04:03 +00:00
1.8 KiB
1.8 KiB
Migration Runbook
Model
- Source of truth: Drizzle schema in
packages/db/src/schema.ts - Generated SQL migrations:
packages/db/drizzle/*.sql - Do not edit generated SQL manually unless required and reviewed.
Local workflow (algorithm)
- Change schema in
packages/db/src/schema.ts. - Generate migration:
bun run db:generate
- Review generated SQL in
packages/db/drizzle/. - Validate migration metadata:
bun run db:check
- Apply migration to target DB:
bun run db:migrate
- Run quality gates:
bun run format:check
bun run lint
bun run typecheck
bun run test
bun run build
- Commit schema + migration files together in one PR.
CI behavior
- CI runs
bun run db:checkin parallel with other quality jobs. - CI does not apply migrations to shared environments.
CD behavior
- CD deploy runs migrations before deploy and now requires the
DATABASE_URLGitHub secret. - If
DATABASE_URLis missing, CD fails fast instead of deploying schema-dependent code without migrations.
Safety rules
- Prefer additive migrations first (new columns/tables) over destructive changes.
- For destructive changes, use two-step rollout:
- Backward-compatible deploy
- Data backfill/cutover
- Cleanup migration
- Never run
db:pushin production pipelines.
Rollback notes
- If a migration fails mid-run, stop deploy and inspect
drizzle.__drizzle_migrationsstate first. - For additive migrations in v1, rollback by:
- Reverting application code to previous release.
- Leaving additive schema in place (safe default).
- For destructive migrations, require explicit rollback SQL script in the same PR before deploy approval.
- Keep one database backup/snapshot before production migration windows.