Database migrations (schema changes) are one of the trickiest parts of CI/CD — unlike stateless application code, databases hold state that can't simply be replaced or rolled back. Handling migrations carefully (automation, backward compatibility, safe patterns) is essential for reliable deployments.
Why database migrations are hard
App code is stateless (replace it, roll back freely). DATABASES hold STATE:
→ can't just "roll back" a migration that dropped a column or transformed data
(the data may be gone) → rollbacks are risky/impossible for destructive changes
→ during deployment, OLD and NEW app code may run SIMULTANEOUSLY (rolling deploy) —
both must work with the database schema at that moment
→ Schema changes need careful coordination with code deployment.
