Skip to content

Commit

Permalink
Merge pull request #71 from umhan35/conditionally-migrate
Browse files Browse the repository at this point in the history
run `diff -q #{release_path}/db/migrate #{current_path}/db/migrate` befo...
  • Loading branch information
kirs committed May 26, 2014
2 parents f32f973 + 343e545 commit ff0eb2b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Some rails specific options.
```ruby
set :rails_env, 'staging' # If the environment differs from the stage name
set :migration_role, 'migrator' # Defaults to 'db'
set :conditionally_migrate, true # Defaults to false
set :assets_roles, [:web, :app] # Defaults to [:web]
set :assets_prefix, 'prepackaged-assets' # Defaults to 'assets' this should match config.assets.prefix in your rails config/application.rb
```
Expand Down
14 changes: 11 additions & 3 deletions lib/capistrano/tasks/migrations.rake
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ namespace :deploy do
desc 'Runs rake db:migrate if migrations are set'
task :migrate => [:set_rails_env] do
on primary fetch(:migration_role) do
within release_path do
with rails_env: fetch(:rails_env) do
execute :rake, "db:migrate"
conditionally_migrate = fetch(:conditionally_migrate)
info '[deploy:migrate] Checking changes in /db/migrate' if conditionally_migrate
if conditionally_migrate && test("diff -q #{release_path}/db/migrate #{current_path}/db/migrate")
info '[deploy:migrate] Skip `deploy:migrate` (nothing changed in db/migrate)'
else
info '[deploy:migrate] Run `rake db:migrate`' if conditionally_migrate
within release_path do
with rails_env: fetch(:rails_env) do
execute :rake, "db:migrate"
end
end
end
end
Expand All @@ -18,6 +25,7 @@ end

namespace :load do
task :defaults do
set :conditionally_migrate, fetch(:conditionally_migrate, false)
set :migration_role, fetch(:migration_role, :db)
end
end

0 comments on commit ff0eb2b

Please sign in to comment.