Skip to content

Latest commit

 

History

History
95 lines (69 loc) · 2.48 KB

File metadata and controls

95 lines (69 loc) · 2.48 KB

Database Migration Rollback Runbook

Overview

This runbook provides step-by-step procedures for rolling back database migrations safely.

Pre-Rollback Checklist

  • Identify the migration to rollback
  • Verify backup exists and is valid
  • Check current database state
  • Notify stakeholders of rollback operation
  • Ensure maintenance window is active
  • Document reason for rollback

Rollback Procedure

Step 1: Assess Current State

# Check migration history
psql -c "SELECT * FROM migration_history ORDER BY executed_at DESC LIMIT 5;"

# Verify current schema version
psql -c "\dt"

Step 2: Create Emergency Backup

./backup_database.sh

Step 3: Execute Rollback Migration

# Execute rollback migration
./migrate.sh down 001_create_products.sql

Step 4: Validate Rollback

# Check table structure
psql -c "\dt"

# Verify data integrity by checking remaining tables
psql -c "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' ORDER BY table_name;"

# Test application connectivity
psql -c "SELECT current_database(), current_user;"

Step 5: Update Documentation

# Record rollback in migration history
psql -c "SELECT * FROM migration_history ORDER BY executed_at DESC;"

# Update status notes if required
psql -c \"UPDATE migration_history
SET notes = COALESCE(notes, '') || E'\nRollback reviewed and documented.'
WHERE migration_name = '001_create_products.sql'
  AND status = 'rolled_back';\"

Post-Rollback Verification

  • Database schema matches expected state
  • Application functions correctly
  • No data loss occurred
  • Performance metrics normal
  • Monitoring alerts cleared

Rollback Decision Matrix

Scenario Action Priority
Syntax error in migration Immediate rollback Critical
Performance degradation Assess impact, rollback if severe High
Data corruption Immediate rollback + restore Critical
Missing dependency Rollback, fix, re-apply Medium

Emergency Contacts

  • Database Administrator: [Contact Info]
  • DevOps Lead: [Contact Info]
  • Application Owner: [Contact Info]

Lessons Learned Template

After each rollback, document:

  1. What went wrong?
  2. Why wasn't it caught in testing?
  3. What changes prevent recurrence?
  4. Update to migration process needed?