1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

場面に応じてdatabaseを切り替える

Last updated at Posted at 2015-08-14

前提

  • masterの取り込みとかでstructure.sqlがしょっちゅうコンフリクトするよ!
  • マイグレーションだけを行うデータベースを作って、そこでrake db:migrateすれば
    きれいに解消されるよ!
  • だけど毎回database.ymlを書き換えるのだるいよ!

なので

以下みたいに記述し切り替えできるようにした

database.yml
development:
  adapter: postgresql
  encoding: utf8
  database: <%=
    if ENV['M']
      'migration' # コンフリクトの解消の為のDB
    else
      'development'
    end.tapp { |db| "connecting #{db}" } # どこに接続してるかを出力
  %> 
  pool: 5
  username: username
  password:

structure.sqlのコンフリクト解消は以下で

$ M=1 bundle exec rake db:migrate

ちなみに、まっさらなDBの状態から始めたい場合は以下で

$ M=1 bundle exec rake db:migrate:reset
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?