Created
May 13, 2013 17:32
-
-
Save MikaelAmborn/5569979 to your computer and use it in GitHub Desktop.
figure out rails rollback STEP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
file_diffs = `bash -c "comm -23 <(git ls-tree -r --name-only #{ENV['environment']}/master:db/migrate) <(git ls-tree -r --name-only HEAD:db/migrate)"`.split | |
if file_diffs.size > 0 | |
puts "Need to do a db rollback before deploying branch" | |
current_env_migrations = `git ls-tree -r --name-only #{ENV['environment']}/master:db/migrate`.split | |
rollback_steps = current_env_migrations.drop_while { |e| !e[/#{file_diffs[0]}/] }.size | |
puts "heroku run rake STEP=#{rollback_steps} db:rollback -a #{ENV['environment']}" | |
`heroku run rake STEP=#{rollback_steps} db:rollback -a #{ENV['environment']}` | |
else | |
puts "No db rollback necessary" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment