Busca en todas las páginas de la documentación
A cookbook for SQL migrations in git with PR review on PostgreSQL 18.4 teams - folder layout, branch policy, and coordination with application deploy order.
# Daily migration work
git checkout main && git pull --ff-only
git checkout -b feat/DB-128-add-orders-priority
# edit db/migrations/V20260709_128__orders_priority.sql
git add db/migrations/
git commit -m "feat(db): add orders.priority column [DB-128]"
git push -u origin feat/DB-128-add-orders-priority
# Open PR with EXPLAIN + rollback sections filleddb/
├── migrations/
│ ├── V20260701_100__baseline.sql
│ ├── V20260709_128__orders_priority.sql
│ └── R__views.sql # repeatable (Flyway)
├── rollback/
│ └── V20260709_128__orders_priority_down.sql
└── seeds/
└── dev_fixtures.sqlWhen to reach for this:
Step 1 - Migration file with metadata
-- V20260709_128__orders_priority.sql
-- Ticket: DB-128
-- Lock risk: medium (CONCURRENTLY index in separate file)
-- Deploy: before orders-api v2.7.0
ALTER TABLE orders ADD COLUMN IF NOT EXISTS priority text NOT NULL DEFAULT 'normal';Step 2 - Separate concurrent index migration
-- V20260709_129__orders_priority_index.sql
-- executeInTransaction=false (Flyway)
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_orders_priority ON orders (priority);Step 3 - PR template checklist
## Database PR
- [ ] Staging flyway migrate applied
- [ ] Lock watch query run during migration
- [ ] Rollback SQL linked
- [ ] App deploy order documented (migration before code)
- [ ] EXPLAIN attached if query/index changeStep 4 - CI migration job
# .github/workflows/db-migrate-staging.yml
- run: flyway -url="${{ secrets.STAGING_JDBC }}" migrate
- run: psql "$STAGING_URL" -c "SELECT version, success FROM flyway_schema_history ORDER BY installed_rank DESC LIMIT 3;"| Branch | Purpose | Migration rule |
|---|---|---|
main | Integration | Only forward migrations that passed staging |
feat/* | Schema feature | One ticket per migration series |
hotfix/* | Prod fix | Cherry-pick migration to main same day |
Correct: migration merge → staging migrate → prod migrate → app deploy
Wrong: app deploy first → code expects missing columnSELECT installed_rank, version, description, success
FROM flyway_schema_history ORDER BY installed_rank DESC LIMIT 5;flyway_schema_history records apply order on each environment| Alternative | Use When | Don't Use When |
|---|---|---|
| Liquibase changelogs | XML/YAML shop standard | Team prefers plain SQL |
| ORM auto-migrate (dev only) | Local prototype | Production |
| Per-service database | Independent migration velocity | Monolith schema |
Many teams forward-only in prod with documented rollback SQL in db/rollback/ not applied automatically. Pick policy in ADR; be consistent.
Platform DBA or bot assigns next VYYYYMMDD_NNN to prevent collision. Never reuse version after merge.
Single schema: one migration repo path. Database-per-service: migrations beside each service. Document in CONTRIBUTING.md.
Stack versions: This page was written for PostgreSQL 18.4, Flyway 10+, and Liquibase 4+.