Created
December 25, 2017 07:32
-
-
Save fukata/bfc63dbcec5d76742323010b7af82461 to your computer and use it in GitHub Desktop.
capistrano + goose
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set :conditionally_migrate, fetch(:conditionally_migrate, false) | |
set :migration_role, fetch(:migration_role, :db) | |
set :migration_servers, -> { primary(fetch(:migration_role)) } | |
namespace :deploy do | |
task :set_app_env do | |
set :app_env, (fetch(:app_env) || fetch(:stage)) | |
end | |
desc 'Runs goose up if migrations are set' | |
task migrate: [:set_app_env] do | |
on fetch(:migration_servers) do | |
conditionally_migrate = fetch(:conditionally_migrate) | |
info '[deploy:migrate] Checking changes in db' if conditionally_migrate | |
if conditionally_migrate && test(:diff, "-qr #{release_path}/db #{current_path}/db") | |
info '[deploy:migrate] Skip `deploy:migrate` (nothing changed in db)' | |
else | |
info '[deploy:migrate] Run `goose up`' | |
# NOTE: We access instance variable since the accessor was only added recently. Once capistrano-rails depends on rake 11+, we can revert the following line | |
invoke :'deploy:migrating' unless Rake::Task[:'deploy:migrating'].instance_variable_get(:@already_invoked) | |
end | |
end | |
end | |
desc 'Runs goose up' | |
task migrating: [:set_app_env] do | |
on fetch(:migration_servers) do | |
within release_path do | |
with app_env: fetch(:app_env) do | |
execute :goose, "-env #{fetch(:app_env)} up" | |
end | |
end | |
end | |
end | |
after 'deploy:updated', 'deploy:migrate' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment