Skip to content

Commit

Permalink
Merge pull request #47 from m-o-e/fix-redo
Browse files Browse the repository at this point in the history
Abort 'redo' when the 'down'-task fails
  • Loading branch information
drujensen authored Dec 15, 2019
2 parents e703f9c + 1a34899 commit b88bfef
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/micrate.cr
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ module Micrate
current = dbversion(db)
previous = previous_version(current, all_migrations.keys)

migrate(all_migrations, current, previous, db)
migrate(all_migrations, previous, current, db)
if migrate(all_migrations, current, previous, db) == :success
migrate(all_migrations, previous, current, db)
end
end

def self.migration_status(db) : Hash(Migration, Time?)
Expand Down Expand Up @@ -96,7 +97,7 @@ module Micrate

if plan.empty?
logger.info "No migrations to run. current version: #{current}"
return
return :nop
end

logger.info "Migrating db, current version: #{current}, target: #{target}"
Expand All @@ -112,10 +113,11 @@ module Micrate

logger.info "OK #{migration.name}"
rescue e : Exception
logger.info "An error ocurred executing migration #{migration.version}. Error message is: #{e.message}"
return
logger.error "An error occurred executing migration #{migration.version}. Error message is: #{e.message}"
return :error
end
end
:success
end

private def self.verify_unordered_migrations(current, status : Hash(Int, Bool))
Expand Down

0 comments on commit b88bfef

Please sign in to comment.