{"canonical_url":"https://engineer.company/ja/portfolio/1022-migrations-behind-a-schema-drift-gate/","content_markdown":"# 1,022件のマイグレーションを差分検査で保護\n\n新規インストールと、インストール後に全マイグレーションを適用する2通りでデータベースを構築し、不一致で失敗するCIゲートを設け、1,022件のマイグレーションにわたるスキーマの整合性を保った。\n\n2025\n\n**状況.** 多くのプロジェクトでは、スキーマを、最初からつくる初期設定と、成長を重ねたマイグレーションの2通りで記述する。同じDBになるはずでも検証がなく、ずれは新環境が本番と違う動作をするまで、たいてい最悪の時点まで、見えなかった。\n\n**課題.** 定期的に同じだと信じるのでなく、自動で同一性を実証する必要があった。\n\n**行動.** 036から1102までの番号を持つ1,022件のマイグレーションで版管理し、順序の規律を地味でも必須とした。CIは毎回、最新の初期スキーマからの構築と、初期スキーマに全移行を順番に再実行する構築を行って比較する。簡単な構造だけでなく投入データも比べる。参照テーブルの誤った補完は列の追加忘れと同じほど有害でも、片方しかスキーマ差分に出ないためだった。不一致は差分を表示してビルドを失敗させる。\n\n**結果.** 新しい環境と長年稼働した環境が同じDBであることを、想定でなく検査した。作成者は再実行でも新規構築でも動く移行を書く必要があり、素早いALTER以上の思考を要する。それが目的であり、別の選択肢は、正しい答えが必要で考える時間がない復元時に初めて知ることだった。\n\n---\n\n- 役割: データベースエンジニア\n- カテゴリー: [データベース](https://platform.engineer.company/ja/categories/databases/), [PostgreSQL](https://platform.engineer.company/ja/categories/postgresql/), [データガバナンス](https://platform.engineer.company/ja/categories/data-governance/), [DevOps](https://platform.engineer.company/ja/categories/devops/), [信頼性・バックアップ](https://platform.engineer.company/ja/categories/reliability/), [移行・モダナイゼーション](https://platform.engineer.company/ja/categories/migration/), [テスト・品質保証](https://platform.engineer.company/ja/categories/testing/)\n- サービス: [データベース管理（DBA）](https://platform.engineer.company/ja/services/database-administration/), [データベース移行・モダナイゼーション](https://platform.engineer.company/ja/services/database-migration/), [AIが使えるデータの整備](https://platform.engineer.company/ja/services/ai-data/), [DevOps・CI/CD自動化](https://platform.engineer.company/ja/services/devops-cicd/)\n\n\u003chttps://engineer.company/ja/portfolio/1022-migrations-behind-a-schema-drift-gate/\u003e\n","date_modified":"2026-11-09T21:50:25Z","description":"2通りでDBを構築し、不一致で失敗するCIゲートで、1,022件のマイグレーションの整合性を維持した。","formats":{"gemtext":"https://platform.engineer.company/ja/portfolio/1022-migrations-behind-a-schema-drift-gate/index.gmi","gopher":"https://platform.engineer.company/ja/portfolio/1022-migrations-behind-a-schema-drift-gate/gophermap","html":"https://platform.engineer.company/ja/portfolio/1022-migrations-behind-a-schema-drift-gate/","json":"https://platform.engineer.company/ja/portfolio/1022-migrations-behind-a-schema-drift-gate/index.json","markdown":"https://platform.engineer.company/ja/portfolio/1022-migrations-behind-a-schema-drift-gate/index.md","pdf":"https://platform.engineer.company/ja/portfolio/1022-migrations-behind-a-schema-drift-gate/index.pdf"},"kind":"page","language":"ja","title":"1,022件のマイグレーションを差分検査で保護","url":"https://platform.engineer.company/ja/portfolio/1022-migrations-behind-a-schema-drift-gate/","version":1}