lib/migration_tools/tasks.rb in migration_tools-0.2.1 vs lib/migration_tools/tasks.rb in migration_tools-0.3.0
- old
+ new
@@ -15,10 +15,16 @@
@group = ENV['GROUP'].to_s
raise "Invalid group \"#{@group}\"" if !@group.empty? && !MIGRATION_GROUPS.member?(@group)
@group
end
+ def group=(group)
+ @group = nil
+ @pending_migrations = nil
+ ENV['GROUP'] = group
+ end
+
def migrator
@migrator ||= ActiveRecord::Migrator.new(:up, 'db/migrate')
end
def pending_migrations
@@ -75,12 +81,27 @@
[ :list, :group ].each do |ns|
namespace ns do
MigrationTools::MIGRATION_GROUPS.each do |migration_group|
desc "#{ns == :list ? 'Lists' : 'Executes' } the migrations for group #{migration_group}"
task migration_group => :environment do
- ENV['GROUP'] = migration_group.to_s
+ self.group = migration_group.to_s
Rake::Task["db:migrate:#{ns}"].invoke
+ Rake::Task["db:migrate:#{ns}"].reenable
end
+ end
+ end
+ end
+ end
+
+ namespace :abort_if_pending_migrations do
+ MigrationTools::MIGRATION_GROUPS.each do |migration_group|
+ desc "Raises an error if there are pending #{migration_group} migrations"
+ task migration_group do
+ self.group = migration_group.to_s
+ Rake::Task["db:migrate:list"].invoke
+ Rake::Task["db:migrate:list"].reenable
+ if pending_migrations.any?
+ abort "Run \"rake db:migrate\" to update your database then try again."
end
end
end
end
end