6

How do you disable db:migrate when doing a cap deploy:cold with Capistrano?

In config/deploy.rb the only reference to deploy:migrate is commented out but it's still attempting to do:

bundle exec rake RAILS_ENV=production  db:migrate
Snowcrash
  • 80,579
  • 89
  • 266
  • 376
  • See this answer: http://stackoverflow.com/questions/28300592/skip-database-migration-while-deploying-rails-application-using-capistrano-3 – monteirobrena Apr 17 '16 at 18:35

3 Answers3

4

I got success by overriding the deploy:migrate method in my config/deploy.rb.

namespace :deploy do
  desc "No ActiveRecord override"
  task :migrate do
  end
end
iHiD
  • 2,450
  • 20
  • 32
2

When re-defining a task in Capistrano v2, the original task was replaced. However the Rake DSL on which Capistrano v3 is built is additive. According to documentation. Under most circumstances, you will simply want to use clear_actions, which removes the specified task’s behaviour, but does not alter it’s dependencies or comments:

namespace :deploy do
  Rake::Task["migrate"].clear_actions
  task :migrate do
    puts "no migration"
  end
end
Alan Wang
  • 552
  • 6
  • 15
  • 1
    The info about the new way of overriding tasks is correct. However the clear_actions line should be Rake::Task["deploy:migrate"]. Otherwise, Capistrano throws an error, can't find "migrate" task. Furthermore, theres no need to the enclosing namespace block. You can disable migrations just adding the line Rake::Task["deploy:migrate"].clear_actions in the deploy.rb file. – alujan May 17 '20 at 10:40
0

I had the same problem. That's why I override it in the Rakefile. Like this:

namespace :db do

  desc "db:migration fakes"
  task :migrate => :environment do
    p 'No. We will not migrate!'
  end

end

Here you can add more logic if you like. You could for example trigger a real migration on certain environments.

Robert Reiz
  • 4,243
  • 2
  • 30
  • 43