Created
June 5, 2009 19:31
-
-
Save siannopollo/124456 to your computer and use it in GitHub Desktop.
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
| # this assumes that it lives in the config directory | |
| set :db_dump_filename, "/tmp/my_app.tar.gz" | |
| namespace :db do | |
| desc 'Copy a remote database to the local development db' | |
| task :copy, :roles => :db, :only => {:primary => true} do | |
| remote_database_yml = capture("cat #{current_path}/config/database.yml") | |
| local_database_yml = File.read(File.dirname(__FILE__) + '/database.yml') | |
| remote_database_config = YAML::load(remote_database_yml)[rails_env] | |
| local_database_config = YAML::load(local_database_yml)['development'] | |
| run "mysqldump #{database_options remote_database_config} | gzip > #{db_dump_filename}" | |
| get db_dump_filename, db_dump_filename | |
| run "rm -f #{db_dump_filename}" | |
| command = "gunzip -c #{db_dump_filename} | mysql #{database_options local_database_config}" | |
| puts "executing `#{command}`" | |
| system command | |
| end | |
| def database_options(config) | |
| options = ["-u #{config['username']}"] | |
| options << "-p#{config['password']}" if config['password'] && !config['password'].blank? | |
| options << "-h #{config['host']}" if config['host'] && !config['host'].blank? | |
| options << "-P #{config['port']}" if config['port'] && !config['port'].blank? | |
| options << "#{config['database']}" | |
| options * ' ' | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment