Skip to content

マイグレーションをAtlasに移行 #1216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
May 5, 2025
Merged

Conversation

ikura-hamu
Copy link
Member

@ikura-hamu ikura-hamu commented May 5, 2025

fix #1139

マイグレーションに Atlas を使うように変更した

  • 🩹 atlas のツール
  • 🔧 localhostからdbにアクセスできるようにする
  • 🏭 現在のスキーマを生成
  • ✨ atlasをアプリに組み込む
  • ✅ データ入れる系マイグレーションのテスト
  • 🩹 wireの設定
  • 🔧 ローカル環境の設定
  • 🩹 本番のイメージにatlas入れる
  • 🩹 データ入れる系のmigrationをSQLでやる
  • 🚧 既存の構造体をいったんコピー
  • 🔧 atlasのローカルの設定
  • 🩹 diffが少なくなるように
  • 🏭 gormの構造体にあわせるマイグレーション
  • 🩹 migrateパッケージの構造体に型エイリアス貼る
  • 🔧 ホットリロードにSQLも含める
  • 🔧 CIでmigrationのLint
  • 🔧 Taskfileにmigrate関係のコマンド追加
  • 📝 マイグレーションのドキュメントを追加

@ikura-hamu ikura-hamu requested a review from Copilot May 5, 2025 09:07
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR migrates the database migration mechanism to use Atlas, updates the DB initialization, and adjusts configuration and CI to support the new migration workflow.

  • Updated table aliases in Gorm migration files to point to new Atlas schema definitions.
  • Integrated migration configuration into DB initialization and tests.
  • Enhanced Docker, Taskfile, and CI configurations for Atlas migration and linting.

Reviewed Changes

Copilot reviewed 24 out of 31 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/repository/gorm2/migrate/current.go Updated table aliases to reference the new Atlas schema definitions
src/repository/gorm2/db_test.go Added migration configuration mocks for Atlas integration tests
src/repository/gorm2/db.go Updated DB initialization to incorporate migration configuration and Atlas
src/config/v1/migration.go, env.go Introduced migration configuration interface and environment variables
src/config/migration.go Added migration interface definition
migrations/export.go Incorporated migration file export using embed.FS
docs/migration.md Updated documentation for Atlas migration usage
docker/dev/compose.yaml, docker/base/compose.yaml Adjusted Docker configs to support Atlas migration and DB access
Taskfile.yml Added new tasks for migration management
.github/workflows/ci.yaml Added a CI job for Atlas migration linting
Files not reviewed (7)
  • atlas.hcl: Language not supported
  • docker/dev/Dockerfile: Language not supported
  • docker/production/Dockerfile: Language not supported
  • go.mod: Language not supported
  • migrations/20250327121655.sql: Language not supported
  • migrations/20250505054607_organize_indices.sql: Language not supported
  • migrations/atlas.sum: Language not supported
Comments suppressed due to low confidence (1)

src/repository/gorm2/migrate/current.go:7

  • [nitpick] The alias 'GameTable' for a v1 table now references 'schema.GameTable2', which could be confusing. Consider clarifying the naming or adding a comment to indicate that v1 and v2 share the same underlying table.
GameTable                   = schema.GameTable2

Copy link

github-actions bot commented May 5, 2025

Migrate lint

Lint output
Error: git diff: exit status 128

Copy link

codecov bot commented May 5, 2025

Codecov Report

Attention: Patch coverage is 1.35135% with 146 lines in your changes missing coverage. Please review.

Project coverage is 49.15%. Comparing base (b52eeb4) to head (8207614).
Report is 23 commits behind head on main.

Files with missing lines Patch % Lines
src/repository/gorm2/schema/migrate.go 0.00% 69 Missing ⚠️
src/repository/gorm2/schema/v2.go 0.00% 30 Missing ⚠️
src/repository/gorm2/schema/schema.go 0.00% 26 Missing ⚠️
src/config/v1/migration.go 0.00% 18 Missing ⚠️
src/wire/wire_gen.go 0.00% 2 Missing ⚠️
src/repository/gorm2/db.go 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1216      +/-   ##
==========================================
- Coverage   49.78%   49.15%   -0.64%     
==========================================
  Files         123      127       +4     
  Lines       11157    11301     +144     
==========================================
  Hits         5555     5555              
- Misses       5304     5448     +144     
  Partials      298      298              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

github-actions bot commented May 5, 2025

Migrate lint

Lint output
Analyzing changes until version 20250505054607 (2 migrations in total):

-- analyzing version 20250327121655
  -- no diagnostics found
-- ok (440.421µs)

-- analyzing version 20250505054607
  -- constraint deletion detected:
    -- L4: Dropping foreign-key constraint
       "fk_edition_game_version_relations_edition_table_v2"
       https://atlasgo.io/lint/analyzers#CD101
    -- L4: Dropping foreign-key constraint
       "fk_edition_game_version_relations_game_version_table2_v2"
       https://atlasgo.io/lint/analyzers#CD101
    -- L6: Dropping foreign-key constraint
       "fk_game_genre_relations_game_genre_table_v10"
       https://atlasgo.io/lint/analyzers#CD101
    -- L6: Dropping foreign-key constraint
       "fk_game_genre_relations_game_genre_table_v11"
       https://atlasgo.io/lint/analyzers#CD101
    -- L6: Dropping foreign-key constraint
       "fk_game_genre_relations_game_genre_table_v12"
       https://atlasgo.io/lint/analyzers#CD101
    -- L6: Dropping foreign-key constraint
       "fk_game_genre_relations_game_genre_table_v13"
       https://atlasgo.io/lint/analyzers#CD101
    -- L6: Dropping foreign-key constraint "fk_game_genre_relations_game_table2_v11"
       https://atlasgo.io/lint/analyzers#CD101
    -- L6: Dropping foreign-key constraint "fk_game_genre_relations_game_table2_v12"
       https://atlasgo.io/lint/analyzers#CD101
    -- L6: Dropping foreign-key constraint "fk_game_genre_relations_game_table2_v13"
       https://atlasgo.io/lint/analyzers#CD101
    -- L6: Dropping foreign-key constraint "fk_game_genre_relations_game_table2_v5"
       https://atlasgo.io/lint/analyzers#CD101
    -- L8: Dropping foreign-key constraint
       "fk_game_version_game_file_relations_game_file_table2_v2"
       https://atlasgo.io/lint/analyzers#CD101
    -- L8: Dropping foreign-key constraint
       "fk_game_version_game_file_relations_game_file_table2_v5"
       https://atlasgo.io/lint/analyzers#CD101
    -- L8: Dropping foreign-key constraint
       "fk_game_version_game_file_relations_game_version_table2_v15"
       https://atlasgo.io/lint/analyzers#CD101
    -- L8: Dropping foreign-key constraint
       "fk_game_version_game_file_relations_game_version_table2_v2"
       https://atlasgo.io/lint/analyzers#CD101
    -- L8: Dropping foreign-key constraint
       "fk_game_version_game_file_relations_game_version_table2_v4"
       https://atlasgo.io/lint/analyzers#CD101
    -- L10: Dropping foreign-key constraint "fk_games_game_versions"
       https://atlasgo.io/lint/analyzers#CD101
    -- L12: Dropping foreign-key constraint
       "fk_launcher_version_game_relations_game_table"
       https://atlasgo.io/lint/analyzers#CD101
-- ok (27.892µs)

-------------------------
-- 367.667385ms
-- 1 version ok, 1 with warnings
-- 38 schema changes
-- 17 diagnostics

@ikura-hamu
Copy link
Member Author

/review

Copy link

github-actions bot commented May 5, 2025

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis ✅

1139 - PR Code Verified

Compliant requirements:

  • マイグレーションをAtlasに移行
  • アプリ起動時の自動マイグレーション実行機能

Requires further human verification:

  • 実際の運用環境でのマイグレーション検証
  • CIでのLint結果とAtlasバージョン依存の確認
⏱️ Estimated effort to review: 5 🔵🔵🔵🔵🔵
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Connection URL Scheme

buildAtlasURLで組み立てているmaria://スキームがAtlasクライアントで正しく解釈されるか確認してください。

url := fmt.Sprintf("maria://%s:%s@%s:%d/%s",
	user,
	pass,
	host,
	port,
	database,
)

return url, nil
Test Field Name

テストコードで追加したGameVersionsV2フィールドがORMマッピングとスキーマに整合しているかを検証してください。

GameVersionsV2: []migrate.GameVersionTable2{
	{
		ID:          uuid.UUID(gameVersionID1),
		GameID:      uuid.UUID(gameID1),
		GameImageID: uuid.UUID(imageID1),
		GameVideoID: uuid.UUID(videoID1),
		Name:        "v1.0.0",

@ikura-hamu ikura-hamu merged commit 82964b1 into main May 5, 2025
10 of 12 checks passed
@ikura-hamu ikura-hamu deleted the dev/migrate_atlas_prepare branch May 5, 2025 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

もうちょっと簡単なマイグレーション方法の検討
1 participant