-
-
Save ryngonzalez/1089817 to your computer and use it in GitHub Desktop.
Standard rails database.yml with additional definition of live database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
development: | |
adapter: mysql2 # must =~ /mysql/ | |
database: adamDb # required | |
username: your_user | |
password: keep_secret | |
live: | |
ssh_user: # optional, use if live system user differs from your dev user | |
host: example.com # required, can be IP | |
adapter: mysql2 # must =~ /mysql/ | |
database: database_name # required | |
username: your_user | |
password: keep_secret |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :db do | |
def command_args(config) | |
abort "Missing database name" if config['database'].blank? | |
args = '' | |
args << "-u #{config['username']} " if config['username'].present? | |
args << "-p#{config['password']} " if config['password'].present? | |
args << config['database'] | |
end | |
task :load_live_data do | |
config = Rails.application.config.database_configuration | |
abort "Missing live db config" if config['live'].blank? | |
dev = config['development'] | |
live = config['live'] | |
abort "Dev db is not mysql" unless dev['adapter'] =~ /mysql/ | |
abort "Live db is not mysql" unless live['adapter'] =~ /mysql/ | |
abort "Missing ssh host" if live['host'].blank? | |
cmd = "ssh -C " | |
cmd << "#{live['ssh_user']}@" if live['ssh_user'].present? | |
cmd << "#{live['host']} mysqldump #{command_args(live)} | " | |
cmd << "mysql #{command_args(dev)}" | |
`#{cmd}` | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment