Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Deal with Irreversible migrations and ensure order of execution

  • Loading branch information...
commit 64ca1a0c5119c8b2cf67c38d281cc6f73e28c725 1 parent 805c578
Rodrigo Kochenburger authored
Showing with 9 additions and 3 deletions.
  1. +9 −3 update_migrations.rb
12 update_migrations.rb
View
@@ -41,16 +41,22 @@ def migrations_for(commit)
exit
end
-(curr - prev).each do |new_mig, name|
- ActiveRecord::Migrator.run(:up, 'db/migrate', new_mig) unless ran.include?(new_mig)
+(curr - prev).sort.each do |new_mig, name|
+ begin
+ ActiveRecord::Migrator.run(:up, 'db/migrate', new_mig) unless ran.include?(new_mig)
+ rescue ActiveRecord::IrreversibleMigration
+ puts "Irreversible migration, skipping it"
+ end
end
-(prev - curr).each do |deleted_mig, name|
+(prev - curr).sort.reverse.each do |deleted_mig, name|
if ran.include?(deleted_mig)
`git checkout #{ARGV[0]} -- db/migrate/#{name}`
begin
ActiveRecord::Migrator.run(:down, 'db/migrate', deleted_mig)
+ rescue ActiveRecord::IrreversibleMigration
+ puts "Irreversible migration, skipping it"
ensure
`git rm -f db/migrate/#{name}`
end
Please sign in to comment.
Something went wrong with that request. Please try again.