Q: How do you handle database migrations in a CI/CD pipeline?
Run migrations as part of the deployment pipeline, but carefully:
#CI/CD #Additional CI/CD Scenarios #L2 #DevOps #Automation #Pipelines
🎙️ Candidate Opening & Architectural Context
""During a high-stakes release, we hit a similar deployment challenge and resolved it with automated safeguards. When addressing this question, I walk the interviewer through our production incident runbook: isolating the blast radius, checking diagnostic logs and metrics, and applying a safe fix.""
Advertisement
🛠️ Production Runbook & Step-by-Step Resolution
1️⃣
Initial Diagnostics & Root Cause Analysis
Run migrations as part of the deployment pipeline, but carefully:
- Migrations run in a pre-deploy job (or init container in K8s) before the new app version starts.
- Always run migrations before the new app version, never after.
- Use backward-compatible migrations — the migration must work with both the old app version AND the new app version (in case of rollback).
2️⃣
Remediation & Permanent Safeguards
Approach: Backward-compatible migration pattern: Never rename a column in one deploy — that breaks the running old-version app. Tools: Flyway, Liquibase, Alembic (Python), Rails migrations.
- Expand: add new column with a default (old app ignores it, new app uses it).
- Contract: remove old column only after old app version is fully gone.
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Pro-Tip: Migrations run in a pre-deploy job (or init container in K8s) before the new app version starts.."
⚡ 60-Second Elevator Pitch Talking Points
- Migrations run in a pre-deploy job (or init container in K8s) before the new app version starts.
- Always run migrations before the new app version, never after.
- Use backward-compatible migrations — the migration must work with both the old app version AND th...
Advertisement