sequel_management.rake can rollback ALL migrations
Closed this issue · 0 comments
maxd commented
git ls-tree --name-only origin/master #{migrations_path}/
command can fail with the following error:
fatal: unsafe repository ('/app' is owned by someone else)
To add an exception for this directory, call:
git config --global --add safe.directory /app
In this case the STDERR
will contains this error message but STDOUT
will be empty (!). You can run the following script to reproduce this situation:
output = `git ls-tree --name-only origin/master ./`
puts
puts "success?=#{$?.success?}"
puts "output=#{output}"
It will print:
fatal: not a git repository (or any of the parent directories): .git
success?=false
output=
So, now look at this code here:
...
original_migrations = `#{git_command}`.split.map { |path| File.basename(path) }
migrations_to_rollback = (migrator.applied_migrations - original_migrations).sort.reverse
...
In case of error the original_migrations
variable will contains empty list of original migrations and migrations_to_rollback
variable will contains all (!) migrations for rollback. So, this code will rollback all migrations in case of error.
I'm going to create PR and add error handling for abort this Rake task in case of error.