セクション E: Atlas / マイグレーション整備#5
Merged
Merged
Conversation
Atlas の GORM provider を `task migrate:diff` から `go run ariga.io/atlas-provider-gorm` で呼び出せるよう、`ariga.io/atlas-provider-gorm` を go.mod の依存として追加した。 本対応により atlas.hcl の `data "external_schema" "gorm"` が internal/shared/model/ をスキャンして desired state を生成できるようになる。 go mod tidy で間接依存も整理した。
Atlas + versioned SQL に統一した DB マイグレーション運用 (Notion 計画 §3 / §7-E) を migrations/README.md にまとめた。 - 開発フロー (task migrate:diff → migrate:lint → migrate:apply:local) - 本番適用フロー (Actions → terraform apply → migrate-job 実行) - baseline 生成手順 (uuid-ossp 拡張と ALTER DEFAULT PRIVILEGES の補完、 atlas schema diff での本番突き合わせ、atlas migrate set による 「適用済み」マーク) - ロールバック方針 (常に前進のみ、image tag 巻き戻し) README に内容ができたため migrations/.gitkeep は削除する。
Contributor
There was a problem hiding this comment.
Pull request overview
Atlas + GORM モデルを source of truth としたマイグレーション運用を成立させるために、desired state 生成のための provider 依存追加と、運用手順ドキュメントを整備するPRです。
Changes:
migrations/README.mdに、開発フロー・本番適用フロー・Phase 1 cutover 用 baseline 手順・ロールバック方針を整理ariga.io/atlas-provider-gormを追加し、GORM モデルから desired state を生成できるように依存関係を更新migrations/.gitkeepを削除して、マイグレーションディレクトリをドキュメント/成果物の置き場として整理
Reviewed changes
Copilot reviewed 2 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| migrations/README.md | Atlas/GORM ベースのマイグレーション運用手順を文書化 |
| migrations/.gitkeep | 運用ドキュメント整備に伴い不要になったため削除 |
| go.mod | atlas-provider-gorm 追加に伴う依存関係更新 |
| go.sum | 依存追加に伴うサム更新 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| task migrate:lint | ||
| ``` | ||
|
|
||
| PR では `migrate-lint.yml` ワークフローが同等の `atlas migrate lint --env local --latest 1` を必須実行する (詳細は `.github/workflows/migrate-lint.yml`)。 |
Comment on lines
+64
to
+70
| GitHub Actions `deploy.yml` が次の順で動く。 | ||
|
|
||
| 1. `terraform apply` で Cloud Run Service / Job (migrate-job 含む) のイメージ tag を更新 | ||
| 2. `gcloud run jobs execute migrate-job<env-suffix> --wait` を実行 | ||
| 3. Cloud Run Job 内で `cmd/migrate-job` が起動し、`cloudsqlconn` 経由で IAM 認証付き接続を確立後、`migrations/` を適用する | ||
|
|
||
| `migrate-job` のタイムアウトは `MIGRATE_TIMEOUT` (デフォルト `10m`) で外側から強制終了される。失敗時は non-zero exit でワークフローも失敗扱い。 |
| atlas migrate diff <name> --env local | ||
| ``` | ||
|
|
||
| - 使い捨て docker postgres (`docker://postgres/16/dev`) が dev DB として起動する |
Comment on lines
21
to
23
| require ( | ||
| ariga.io/atlas-provider-gorm v0.6.0 // indirect | ||
| cel.dev/expr v0.25.1 // indirect |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
やったこと
Notion 計画 §7-E の Atlas / マイグレーション整備分。Atlas プロジェクト設定そのものは §A の
atlas.hclと Taskfile (migrate:diff/migrate:lint/migrate:apply:local) で雛形済みのため、本 PR では desired state を読み取る provider 依存と運用ドキュメントを整備する。ariga.io/atlas-provider-gormをgo getで追加し、atlas.hclのdata "external_schema" "gorm"からgo runで呼び出せる形にするinternal/shared/model/を--path指定で scan する手順をローカル動作確認 (Postgres 方言で全テーブル DDL が出力されることを確認)migrations/README.mdに開発フロー (task migrate:diff→migrate:lint→migrate:apply:local) を整理terraform apply→migrate-job実行) を文書化atlas migrate diff baseline→uuid-ossp拡張とALTER DEFAULT PRIVILEGES補完 →atlas schema diffで本番突き合わせ →atlas migrate setで「適用済み」マーク) を明記migrations/.gitkeepを削除確認したこと
mise exec -- go run ariga.io/atlas-provider-gorm load --path ./internal/shared/model --dialect postgresが GORM モデルから Postgres DDL を出力することを確認 (78 行)mise exec -- go build ./...が成功メモ
atlas migrate diff baseline自体は dev DB (Docker postgres) を必要とするため本 PR の CI 環境では生成しない。Cloud SQL / dev DB 接続が可能になり次第、migrations/README.mdの手順に沿ってmigrations/<ts>_baseline.sqlを別 PR で起こすatlas-provider-gormの auto-discovery はinternal/shared/model/Common埋め込み構造体を独立テーブル (commons) として誤認識する既知の癖がある。baseline 生成時に手動除外する旨は README に明記してあるatlas migrate lintを PR 必須化する.github/workflows/migrate-lint.ymlは §G で追加するcmd/migrate-jobのリビジョン管理テーブル選定 (atlas_schema_revisions) は §A の TODO のまま残置 (本 PR のスコープ外)feat/d-batch-jobs