1.5 KiB
1.5 KiB
Database Migration Safety Guidelines
Principles
- Additive changes only: Production migrations should only add new columns, tables, or indexes
- No destructive changes: Never DROP columns or tables in production migrations
- Two-phase migrations: For destructive changes, use a two-phase approach:
- Phase 1: Add new schema, deploy code to use it
- Phase 2: Remove old schema after code is stable
Migration Process
Before Migration
- Test migration on staging database
- Verify application works with new schema
- Take database backup
- Document rollback procedure
During Migration
- Run migration in dry-run mode first
- Apply migration to production
- Verify migration completed successfully
- Monitor application for errors
After Migration
- Verify all queries work correctly
- Monitor performance metrics
- Update documentation if needed
Rollback Procedures
Emergency Rollback
- Stop application deployment
- Restore database from backup
- Revert to previous application version
- Verify application functionality
Planned Rollback
- Deploy previous application version
- Run rollback migration
- Verify application functionality
- Update monitoring dashboards
Migration Checklist
- Migration tested on staging
- Backup taken before production migration
- Rollback procedure documented
- Team notified of maintenance window
- Monitoring dashboards prepared
- Support team on standby