-
Notifications
You must be signed in to change notification settings - Fork 0
Fix/make gameversion unique #1090
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
Conversation
This reverts commit 1a80a4d.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1090 +/- ##
==========================================
- Coverage 51.16% 51.09% -0.07%
==========================================
Files 122 123 +1
Lines 11060 11116 +56
==========================================
+ Hits 5659 5680 +21
- Misses 5061 5092 +31
- Partials 340 344 +4 ☔ View full report in Codecov by Sentry. |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
|
@ikura-hamu |
|
(まだ中身見てないです) |
ikura-hamu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
実装ありがとう、そこそこ難しかったと思いますが、とてもきれいに書かれていました。
repositoryのCreateGameVersionで、ユニーク制約に違反していたらrepository.ErrDuplicatedKeyを返すようにしてください。game_genre.goのUpdateGameGenreが分かりやすいと思います。
| GameID uuid.UUID `gorm:"type:varchar(36);not null;index:idx_game_id_name,unique"` // GameIDとNameの組み合わせでuniqueに | ||
| GameImageID uuid.UUID `gorm:"type:varchar(36);not null"` | ||
| GameVideoID uuid.UUID `gorm:"type:varchar(36);not null"` | ||
| Name string `gorm:"type:varchar(32);size:32;not null;uniqueIndex:idx_game_id_name"` // GameIDとNameの組み合わせでuniqueに |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ユニークインデックスを貼るところの記法をindex:idx_game_id_name,uniqueとuniqueIndex:idx_game_id_nameのどちらかで固定してほしいです。
src/repository/gorm2/migrate/v15.go
Outdated
|
|
||
| // 複合ユニーク制約を追加 | ||
| if err := tx.Exec( | ||
| "ALTER TABLE v2_game_versions ADD CONSTRAINT unique_game_version_per_game UNIQUE (game_id, name)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AutoMigrateを実行すると、定義した構造体に合うようにスキーマやインデックスが変更されるので、ここのExecは不要です
src/repository/gorm2/migrate/v15.go
Outdated
| return err | ||
| } | ||
| // テーブル定義をロールバック | ||
| if err := tx.Migrator().DropTable(&gameVersionTable2V15{}); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DropTableしちゃうとテーブルが消えて終わってしまうので、上のユニーク制約削除だけで十分です。
src/service/v2/game_version.go
Outdated
| } | ||
|
|
||
| // 既存のゲームバージョンの名前と一致していた場合はエラーを返す | ||
| _, currentGameVersions, err := gameVersion.gameVersionRepository.GetGameVersions(ctx, gameID, 0, 0, repository.LockTypeNone) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここでゲームのバージョンを全て取ってきてしまうと、例えば1つのゲームに10000個のバージョンがあったときにめっちゃ遅くなってしまうので、
- gameIDと名前を指定して取得するメソッドをrepositoryの方で作って使う
- 下の方のCreateGameVersionで返って来るエラーが
repository.ErrDuplicatedUniqueKeyかどうかを判定する
のどちらかでやってほしいです。
| return echo.NewHTTPError(http.StatusBadRequest, "invalid fileType") | ||
| case errors.Is(err, service.ErrNoAsset): | ||
| return echo.NewHTTPError(http.StatusBadRequest, "no assets") | ||
| case errors.Is(err, service.ErrDuplicateGameVersion): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
serviceのinterfaceに書かれたCreateGameVersionのところに、ErrDuplicateGameVersionを返すことがあるとコメントで書いておいてください。
|
レビューありがとうございました!少し遅くなってしまいましたが,ご指摘いただいた点について修正いたしましたので,際レビューお願いいたします |
ikura-hamu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ごめん、前回のコメントの仕方が微妙だったかも。
repositoryのCreateGameVersionで、ユニーク制約に違反していたらrepository.ErrDuplicatedKeyを返すようにしてください。game_genre.goのUpdateGameGenreが分かりやすいと思います
repository/gorm2の実装でこれの修正もお願いします。
src/service/v2/game_version.go
Outdated
| } | ||
|
|
||
| // 既存のゲームバージョンの名前と一致していた場合はエラーを返す | ||
| // _, currentGameVersions, err := gameVersion.gameVersionRepository.GetGameVersions(ctx, gameID, 0, 0, repository.LockTypeNone) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここがコメントアウトなのは何か意図がありますか?なければ消しちゃってください
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
すみません,消し忘れです:pray:
|
ご指摘ありがとうございます!修正いたしましたので,ご確認お願いいたします。 |
ikura-hamu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ありがとう、お疲れ様でした
User description
やったこと
テストが落ちているところがあるのでそれを修正したいのですが詰まり気味になってしまったので,一旦DraftでPRを出させていただいて今度の進捗会の際にご相談させていただければと思います。
close #1071
PR Type
Bug fix, Tests, Enhancement
Description
ゲームバージョン名が重複しないようにユニーク制約を追加
重複する既存データをリネームするマイグレーションを実装
重複したバージョン名のエラーハンドリングを追加
重複エラーに関するテストケースを追加
Changes walkthrough 📝
game_version.go
重複エラーのハンドリングを追加src/handler/v2/game_version.go
game_version_test.go
重複エラーのテストケースを追加src/handler/v2/game_version_test.go
v2_game_version_test.go
重複エラーのテストケース修正src/repository/gorm2/v2_game_version_test.go
game_version_test.go
重複エラーのテストケース追加src/service/v2/game_version_test.go
current.go
マイグレーションバージョンの更新src/repository/gorm2/migrate/current.go
migrate.go
新しいマイグレーションの追加src/repository/gorm2/migrate/migrate.go
v15.go
v2_game_versionsテーブルのユニーク制約追加src/repository/gorm2/migrate/v15.go
game_version.go
重複バージョン名のチェックを追加src/service/v2/game_version.go