LoginSignup
2
1

More than 3 years have passed since last update.

Railsの `rake db:create` をリモートでもできるようにする

Last updated at Posted at 2016-06-03

rake db:createlocalhostのDBの作成をしてくれるがリモートのDBでは利用できない.
ただ設定で1行追加するだけでリモートのDBでもこのタスクが使える様になります.

以下の例はリモートのDBのIPが192.168.99.100の場合の例です.

config/initializers/localhosts.rb
ActiveRecord::Tasks::DatabaseTasks::LOCAL_HOSTS << '192.168.99.100'

具体的にはdatabase_tasks.rbで以下の様に定義されています。
この定義を良く見るとfreezeしているわけではないので追加できます.

/activerecord/lib/active_record/tasks/database_tasks.rb#L55
LOCAL_HOSTS = ["127.0.0.1", "localhost"]

Githubのmasterブランチでも使える感じだったので、Rails6系でも使えると思う.

2
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
2
1