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
That's a great answer from Andres Jaan Tack. I just wanted to add a few comments.
Firstly, here's an improved version of Andres' deploy:load_schema
task which includes a warning, and more importantly uses bundle exec
and RAILS_ENV
to ensure that the environment is set up correctly:
namespace :deploy do
desc 'Load DB schema - CAUTION: rewrites database!'
task :load_schema, :roles => :app do
run "cd #{current_path}; bundle exec rake db:schema:load RAILS_ENV=#{rails_env}"
end
end
I have submitted a feature request to have deploy:load_schema implemented in Capistrano. In that request, I noted that the 'db:schema:load vs. db:migrate' debate has already been covered in the Capistrano discussion group, and there was some reluctance to switch the deploy:cold
task to using db:schema:load
over db:migrate
, since if run unintentionally, the former nukes the entire database whereas the latter would probably complain and bail harmlessly. Nevertheless db:schema:load
is technically the better approach, so if the risk of accidental data loss could be mitigated, it would be worth switching.