Sha256: 18bd55a153ec06057e13219297a537b1b106273ee1ea9ed19bcd19bc9db48989

Contents?: true

Size: 1.39 KB

Versions: 6

Compression:

Stored size: 1.39 KB

Contents

load File.expand_path("../set_rails_env.rake", __FILE__)

namespace :deploy do

  desc 'Runs rake db:migrate if migrations are set'
  task :migrate => [:set_rails_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 `rake db:migrate`'
        # 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 rake db:migrate'
  task migrating: [:set_rails_env] do
    on fetch(:migration_servers) do
      within release_path do
        with rails_env: fetch(:rails_env) do
          execute :rake, 'db:migrate'
        end
      end
    end
  end

  after 'deploy:updated', 'deploy:migrate'
end

namespace :load do
  task :defaults do
    set :conditionally_migrate, fetch(:conditionally_migrate, false)
    set :migration_role, fetch(:migration_role, :db)
    set :migration_servers, -> { primary(fetch(:migration_role)) }
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
capistrano-rails-1.5.0 lib/capistrano/tasks/migrations.rake
capistrano-rails-1.4.0 lib/capistrano/tasks/migrations.rake
capistrano-rails-1.3.1 lib/capistrano/tasks/migrations.rake
capistrano-rails-1.3.0 lib/capistrano/tasks/migrations.rake
capistrano-rails-1.2.3 lib/capistrano/tasks/migrations.rake
capistrano-rails-1.2.2 lib/capistrano/tasks/migrations.rake