Skip to content

Instantly share code, notes, and snippets.

@tmiller
Created January 9, 2014 17:02
Show Gist options
  • Save tmiller/8337790 to your computer and use it in GitHub Desktop.
Save tmiller/8337790 to your computer and use it in GitHub Desktop.
Rollback migrations to master from HEAD or a ref
#!/bin/sh
if test -n "$1"; then
ref="$1"
else
ref="HEAD"
fi
git diff $ref --not master --name-only -- db/migrate/ |
cut -d/ -f3 |
cut -d_ -f1 |
sort -r |
xargs -I% -n1 bundle exec rake db:migrate:down VERSION=%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment