Skip to content

Instantly share code, notes, and snippets.

@paneq
Created April 9, 2012 17:34
Show Gist options
  • Save paneq/2344900 to your computer and use it in GitHub Desktop.
Save paneq/2344900 to your computer and use it in GitHub Desktop.
My fix for local database definition in rails
namespace :db do
def local_database?(config, &block)
if config['host'].in?(['127.0.0.1', 'localhost', '192.168.30.1']) || config['host'].blank?
yield
else
$stderr.puts "This task only modifies local databases. #{config['database']} is on a remote host."
end
end
end
@eoinkelly
Copy link

FYI

# config/application.rb
ActiveRecord::Tasks::DatabaseTasks::LOCAL_HOSTS << "192.168.99.100" # <-- IP of your docker-host

also works (tested in rails 4.2).

@jruz
Copy link

jruz commented Apr 5, 2016

Thanks! 👍

@slavikdev
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment