Database migrations tested on staging or test database before production
Why it matters
Applying untested database migrations directly to production risks table corruption, constraint violations, or data loss that cannot be easily undone. NIST CP-9 and SOC 2 A1.2 require verified recovery procedures for data; a migration that drops a column or alters a type without pre-testing can trigger application errors for every user and may require hours of manual data recovery. ISO 25010 reliability.recoverability demands that any data-modifying operation be validated before it reaches the primary store.
Severity rationale
High because a failed migration in production can corrupt live data or take down the application for all users, with recovery time measured in hours if no pre-tested rollback path exists.
Remediation
Run migrations against a test or staging database as a CI/CD step before the production deployment step. For Prisma:
# .github/workflows/test.yml
- name: Test migrations on staging DB
run: |
export DATABASE_URL="postgres://test:test@localhost:5432/test_db"
npx prisma migrate deploy
Document the rollback path in DEPLOYMENT.md:
## Migration Rollback
1. Check migration status: `npx prisma migrate status`
2. Mark as rolled back: `npx prisma migrate resolve --rolled-back <migration-name>`
3. Fix the migration file, then re-deploy: `npx prisma migrate deploy`
For destructive migrations (column drops, type changes), take a point-in-time snapshot immediately before the production deployment step.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Deployment Readiness Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- iso-25010:2011 · reliability.recoverability — Recoverability — database migration rollback capability
- nist:rev5 · CP-9 — System Backup
- soc2:2017 · A1.2 — Availability — capacity and performance monitoring, change management
Taxons
History
- 2026-04-18·v1.0.0·Initial import from deployment-readiness·automated