Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace :db do
- desc 'Pull production db to current environment'
- task pull: [:drop, :create, :dump, :restore, 'test:prepare']
- task :dump do
- dumpfile = "#{Rails.root}/tmp/latest.dump"
- puts 'Dumping the production motherload...'
- system "cx run -s discovered -e production '#{dump_command}' > #{dumpfile}"
- puts 'Done dumping!'
- end
- task :restore do
- config = Rails.application.config.database_configuration[Rails.env]
- dumpfile = "#{Rails.root}/tmp/latest.dump"
- puts "importing production database to #{Rails.env} database..."
- system "#{restore_command(config)} < #{dumpfile}"
- puts 'Done!'
- end
- def dump_command
- options = ['mysqldump']
- options << "--user #{ENV['PRD_MYSQL_USER']}"
- options << "--password=#{ENV['PRD_MYSQL_PASSWORD']}"
- options << '--host=127.0.0.1'
- options << '--add-drop-table --skip-lock-tables --verbose discovered'
- options.join(' ')
- end
- def restore_command(config)
- options = ['mysql']
- options << "--host=#{config['host']}"
- options << "--user=#{config['username']}"
- options << "--password=#{config['password']}" if config['password']
- options << config['database']
- options.join(' ')
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement