環境
Ruby on Railsのアプリをgitを利用し、開発しています。
フレームワーク: Ruby on Rails 4.2
言語: ruby 2.2.5
データベース: PostgreSQL v9.6.1
実現したいこと
他のbranchのschema情報を config/schema.rb
へ反映を抑制したい
###発生している問題・エラーメッセージ
現象
branch_a
でrails g migration
を実行し、rake db:migrate
で、 DBへ反映git checkout branch_b
でbranch_b
に切り替え、rake db:migrate
を行う
=> branch_a
で作成したDBの情報が config/schema.rb
に反映されてしまうため、
不要なdiffができてしまう。
詳細な手順
branch_a
でrails g migration
を実行し、rake db:migrate
で、 DBへ反映
$ git branch * branch_a branch_b master $ rails g model user name:string invoke active_record create db/migrate/20170119014258_create_users.rb create app/models/user.rb invoke test_unit create test/models/user_test.rb create test/fixtures/users.yml $ rake db:migrate == 20170119014258 CreateUsers: migrating ====================================== -- create_table(:users) -> 0.0481s == 20170119014258 CreateUsers: migrated (0.0482s) ============================= $ git status On branch branch_a Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: db/schema.rb Untracked files: (use "git add <file>..." to include in what will be committed) app/models/user.rb db/migrate/20170119014258_create_users.rb test/fixtures/users.yml test/models/user_test.rb $ git add . $ git commit -m "add user model"
2.git checkout branch_b
で branch_b
に切り替え、 rake db:migrate
を行う
$ git checkout -b branch_b $ git branch branch_a * branch_b master $ rake db:migrate #←ここでdiffが発生する $ git diff diff --git a/db/schema.rb b/db/schema.rb index 305532e..1c0d0dc 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20161230062212) do +ActiveRecord::Schema.define(version: 20170119014258) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -29,4 +29,10 @@ ActiveRecord::Schema.define(version: 20161230062212) do t.datetime "updated_at", null: false end + create_table "users", force: :cascade do |t| + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + end
現在の対応方法
branch_a
で rake db:migrate:down VERSION=xxx
でDBのschemaを元に戻してから、
branch_b
へ切り替えるようにしています。
このような場合、皆さんどのように開発されてますか?
良い方法があればご教示ください
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/01/19 01:54