capistrano / laravel

Gem for deploying Laravel projects with capistrano v3.*
MIT License
222 stars 71 forks source link

How/Where would I set migrations to run on each deploy? #49

Closed louisl closed 5 years ago

louisl commented 6 years ago

I have everything working nicely but I have to ssh in to run the migrations at the moment.

tedslittlerobot commented 5 years ago

You can set arbitrary commands to run at certain points in the deployment process.

In your config/deploy.rb file:

namespace :deploy do

  after :updated, :migrate do
    on roles(:all) do
      within release_path do
        execute :php, :artisan, :migrate, fetch(:laravel_artisan_flags), '--force'
      end
    end
  end

end
louisl commented 5 years ago

Thanks for the info.

tedslittlerobot commented 5 years ago

was in a rush the other day, but to give a bit more information around what this solution does:

in the following snippet:

after :updated, :migrate do

So you could then have:

before :migrate, :sometask do
  # something to run before migrations ...
end

Pretty much the only two events i've ever used are:

The default capistrano hooks are here - https://capistranorb.com/documentation/getting-started/flow/ if you want more. This capistrano/laravel package has its own event hooks too (the ones starting with laravel: in https://github.com/capistrano/laravel#tasks)

louisl commented 5 years ago

Thank you for the additional info, that's given me a better understanding of it.