Skip to content

moviesテーブルの適用済みのマイグレーションファイルが誤って修正されてschema.rbと不整合が起きている #9285

@ryufuta

Description

@ryufuta

概要

db/migrate/20240321092012_create_movies.rbを作成・適用後に別のPRで同ファイルに不要な変更を加えている。
変更後にマイグレーションをやり直している訳ではないためschema.rbは正しい状態になっている。

  • マイグレーションファイルを追加したPRは2025-04-02のリリースブランチでリリース
  • マイグレーションファイルを変更したPRは2025-05-20のリリースブランチでリリース

しているため、本番環境でも正しいマイグレーションファイルのみが適用されており問題はない。
単にschema.rbとマイグレーションファイルに不整合が起きているだけ。

※後から別のPRで加えられた変更が不要という根拠
元のPRの c9eed32 のコミットに最終的には採用されなかったマイグレーションの内容がある。
別のPRでマイグレーションファイルを変更したコミット d84d702 を見るとmainブランチの変更を取り込んだ際にコンフリクトの解消に失敗して上のコミットの内容の一部を誤って取り込んだと思われる。

不整合が起きていることの確認手順

  1. 開発環境でbin/rails db:migrate:resetを実行してマイグレーションを最初からやり直す
  2. db/schema.rbに変更が生じ、diffを確認すると以下のように変更後のマイグレーションファイルの内容が反映されていることを確認する
@@ -521,11 +517,14 @@ ActiveRecord::Schema.define(version: 2025_09_05_025850) do
   create_table "movies", force: :cascade do |t|
     t.string "title", null: false
     t.text "description"
-    t.bigint "user_id"
+    t.string "tag_list"
+    t.bigint "user_id", null: false
+    t.bigint "practice_id"
     t.datetime "created_at", precision: 6, null: false
     t.datetime "updated_at", precision: 6, null: false
     t.boolean "wip", default: false, null: false
     t.datetime "published_at"
+    t.index ["practice_id"], name: "index_movies_on_practice_id"
     t.index ["user_id"], name: "index_movies_on_user_id"
   end

(中略)
@@ -1036,6 +1032,7 @@ ActiveRecord::Schema.define(version: 2025_09_05_025850) do
   add_foreign_key "learning_times", "reports"
   add_foreign_key "linear_scales", "survey_questions"
   add_foreign_key "micro_reports", "users"
+  add_foreign_key "movies", "practices"
   add_foreign_key "movies", "users"
   add_foreign_key "notifications", "users"
   add_foreign_key "notifications", "users", column: "sender_id"

やること

関連

該当するマイグレーションファイルを追加したPR: #7535
該当するマイグレーションファイルを変更したPR: #8350

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

完成

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions