malcoauri
malcoauri

Reputation: 12189

Task to execute migrations after publishing app in Capistrano

There is the following 'deploy.rb' code:

namespace :deploy do

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      # Your restart mechanism here, for example:
      execute :touch, release_path.join('tmp/restart.txt')
    end
  end

  after :publishing, :restart
end

This code deploys my app and then restarts my server, but there are some pending migrations after deploy. Can I add task to execute migrations automatically after uploading code? Thanks in advance.

Upvotes: 1

Views: 641

Answers (1)

Yann VERY
Yann VERY

Reputation: 1819

Capistrano 2

If you want to run migrations everytime you deploy, add in your deploy.rb :

after "deploy:update_code", "deploy:migrate"

Or instead of modify deploy.rb, you can call cap deploy:migrations, this will run all pending migrations after your deploy

Capistrano 3

I presume you have installed capistano-rails gem.

If you want to run migrations automaticaly you can required in your Capfile

require 'capistrano/rails/migrations'

Or just run cap deploy:migrate

Sources : https://github.com/capistrano/rails#capistranorails and http://www.talkingquickly.co.uk/2014/01/deploying-rails-apps-to-a-vps-with-capistrano-v3/

Hope this helps

Upvotes: 2

Related Questions