I have a rails app that I\'m moving to another server and I figure I should use db:schema:load to create the mysql database because it\'s recommended. My problem is that I\'m u
Climbing up on the shoulders of Andres Jaan Tack, Adam Spiers, and Kamiel Wanrooij, I've built the following task to overwrite deploy:cold.
task :cold do
transaction do
update
setup_db #replacing migrate in original
start
end
end
task :setup_db, :roles => :app do
raise RuntimeError.new('db:setup aborted!') unless Capistrano::CLI.ui.ask("About to `rake db:setup`. Are you sure to wipe the entire database (anything other than 'yes' aborts):") == 'yes'
run "cd #{current_path}; bundle exec rake db:setup RAILS_ENV=#{rails_env}"
end
My enhancements here are...
transaction do, so that Capistrano will do a proper rollback after aborting.db:setup instead of db:schema:load, so that if the database doesn't already exist, it will be created before loading the schema.