データベースマイグレーション(スキーマ変更)は、CI/CDの中で最も扱いの難しい部分の一つです——ステートレスなアプリケーションコードとは異なり、データベースは単純に置き換えたりロールバックしたりできない 状態(state) を保持します。マイグレーションを慎重に扱うこと(自動化、後方互換性、安全なパターン)が、信頼性の高いデプロイには不可欠です。
なぜデータベースマイグレーションは難しいのか
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.
