Skip to content

Instantly share code, notes, and snippets.

@amw
Created December 21, 2010 16:12
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save amw/750129 to your computer and use it in GitHub Desktop.
Save amw/750129 to your computer and use it in GitHub Desktop.
Standard rails database.yml with additional definition of live database
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
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