Advertisement
Guest User

Untitled

a guest
Jan 5th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. namespace :db do
  2. desc 'Pull production db to current environment'
  3. task pull: [:drop, :create, :dump, :restore, 'test:prepare']
  4.  
  5. task :dump do
  6. dumpfile = "#{Rails.root}/tmp/latest.dump"
  7. puts 'Dumping the production motherload...'
  8. system "cx run -s discovered -e production '#{dump_command}' > #{dumpfile}"
  9. puts 'Done dumping!'
  10. end
  11.  
  12. task :restore do
  13. config = Rails.application.config.database_configuration[Rails.env]
  14.  
  15. dumpfile = "#{Rails.root}/tmp/latest.dump"
  16. puts "importing production database to #{Rails.env} database..."
  17. system "#{restore_command(config)} < #{dumpfile}"
  18. puts 'Done!'
  19. end
  20.  
  21. def dump_command
  22. options = ['mysqldump']
  23. options << "--user #{ENV['PRD_MYSQL_USER']}"
  24. options << "--password=#{ENV['PRD_MYSQL_PASSWORD']}"
  25. options << '--host=127.0.0.1'
  26. options << '--add-drop-table --skip-lock-tables --verbose discovered'
  27.  
  28. options.join(' ')
  29. end
  30.  
  31. def restore_command(config)
  32. options = ['mysql']
  33. options << "--host=#{config['host']}"
  34. options << "--user=#{config['username']}"
  35. options << "--password=#{config['password']}" if config['password']
  36. options << config['database']
  37.  
  38. options.join(' ')
  39. end
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement