railsを実行するたびにrake db:migrate
、schema.rbファイルを変更することにしました。これが完全に合理的な場合もありますが、理由もなく実行しているように見える場合もあります。私が混乱しているのは、gitから新しい移行と新しいバージョンのschema.rbをプルしてから、を実行する場合rake db:migrate
です。この移行には新しいバージョンのschema.rbファイルが付属しているため、schema.rbを更新するべきではありません。ただし、レールは毎回それを変更します。これが発生すると、次のような信じられないほどばかげた変更が見つかります。
add_index "my_table", ["column1", "column2"], :name => "index_on_some_columns"
に
add_index "my_table", ["column2", "column1"], :name => "index_on_some_columns"
これが起こったとき、私はただ走っgit checkout db/schema.rb
て人生を続けますが、それは私を終わりのないものにします。これを行う理由はありますか?また、どうすればこれを防ぐことができますか?
編集:これはdiffからの抜粋です
@@ -165,12 +165,11 @@ ActiveRecord::Schema.define(:version => 20130206001907) do
t.column "updated_at", :datetime
- t.column "coordinates", :point, :srid => 4326
@@ -200,15 +199,16 @@ ActiveRecord::Schema.define(:version => 20130206001907) do
t.column "something", :boolean
+ t.column "coordinates", :point, :srid => 4326
+ t.column "random_string", :string
t.column "remote", :string
- t.column "random_string", :string
end
- add_index "my_table", ["id", "foreign_id"], :name => "index_active_my_table_on_foreign_and_id"
- add_index "my_table", ["id", "active"], :name => "index_my_table_on_active_and_id"
- add_index "my_table", ["id", "content_modified_at"], :name => "index_my_table_on_content_modified_at_and_id"
+ add_index "my_table", ["foreign_id", "id"], :name => "index_active_my_table_on_foreign_and_id"
+ add_index "my_table", ["active", "id"], :name => "index_my_table_on_active_and_id"
+ add_index "my_table", ["content_modified_at", "id"], :name => "index_my_table_on_content_modified_at_and_id"