ActiveHash/YAML から ActiveRecord/PostgreSQL へのDB移行#14
Merged
Conversation
6b21fba to
d0dde37
Compare
9da5f9a to
3b7036d
Compare
d0dde37 to
118f057
Compare
3b7036d to
a9a7304
Compare
118f057 to
df370f2
Compare
a9a7304 to
ea6df28
Compare
df370f2 to
12ed79a
Compare
ea6df28 to
45015a3
Compare
12ed79a to
8270ee7
Compare
45015a3 to
a0c5cb7
Compare
8270ee7 to
6f996eb
Compare
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ActiveRecord 移行後は DB が真実の源になるため、YAML から消えたレコードが 残り続けないよう child-first で destroy_all する削除フェーズを追加。 また途中失敗時のデータ破損を防ぐため全処理を transaction で囲んだ。 README のセットアップ手順にも db:seed を明示した。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
a0c5cb7 to
66be6ac
Compare
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.
要約
Issue #13(ActiveHash/YAML → ActiveRecord/PostgreSQL へのDB移行)を解決する。
ActiveYaml::Base→ApplicationRecordに移行find_or_initialize_by(id:)+assign_attributesで再シード可能にactive_hashgem を完全に削除Closes #13
実装してみて発生した追加判断
find_or_initialize_by(id:)+assign_attributesで実装:upsert_allではなくこの方式を採用した。YAML の id を保持しながら再シードでレコードを更新できること、モデルバリデーションを通過させてデータ品質を保証できることが理由。シード後に PostgreSQL シーケンスをsetvalで補正し、id 指定 insert 後の自動採番ズレを防ぐreverse_eachで子テーブルから順に「YAML に存在しない id」を destroy_all する3フェーズ構成(削除→upsert→シーケンスリセット)に変更metered_only?の業務的不変条件のみ残したテストケース一覧
spec/models/— FactoryBot ベースに書き換え(23 examples)Provider(2 examples)
Plan(7 examples)
AmpereBasedRate(6 examples)
UsageBasedRate(8 examples)
spec/data_consistency_spec.rb— ActiveRecord 版に書き換え(8 examples)