Permalink
Browse files

README and monitor_migrations

  • Loading branch information...
1 parent 5371433 commit 8b2eaad39e6c3eb552c2ac7bb9957cd27c3499ba Kali Donovan committed Nov 14, 2011
Showing with 13 additions and 0 deletions.
  1. +13 −0 lib/capistrano-conditional/deploy.rb
View
13 lib/capistrano-conditional/deploy.rb
@@ -12,6 +12,19 @@ def self.register(name, opts, &block)
@@conditionals << Capistrano::Conditional::Unit.new(name, opts, block)
end
+ def self.monitor_migrations!
+ if ARGV.any?{|v| v['deploy:migrations']} # If running deploy:migrations
+ # If there weren't any changes to migrations or the schema file, then abort the deploy
+ ConditionalDeploy.register :unneeded_migrations, :none_match => ['db/schema.rb', 'db/migrate'] do
+ abort "You're running migrations, but it doesn't look like you need to!"
+ end
+ else # If NOT running deploy:migrations
+ # If there were changes to migration files, run migrations as part of the deployment
+ ConditionalDeploy.register :forgotten_migrations, :any_match => ['db/schema.rb', 'db/migrate'], :msg => "Forgot to run migrations? It's cool, we'll do it for you." do
+ after "deploy:update_code", "deploy:migrate"
+ end
+ end
+ end
def self.apply_conditions!(deployed)
conditional = self.new(deployed)

0 comments on commit 8b2eaad

Please sign in to comment.