Created
August 31, 2018 08:45
-
-
Save tonidezman/736f6b89d1d9e07a85ecc726b1516b60 to your computer and use it in GitHub Desktop.
Script for detecting if we need to rollback migrations when switching branches
This file contains hidden or 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
# This git hook script helps us detect if we need to | |
# rollback some migrations when switching branches | |
# Recipe: | |
# 1) cd /path/to/your/repo | |
# 2) touch .git/hooks/post-checkout | |
# 3) chmod u+x .git/hooks/post-checkout | |
# 4) add code below to the post-checkout file | |
#!/bin/bash | |
set -e | |
set -u | |
echo "Inside git post-checkout hook" | |
echo "Running rake db:migrate:status" | |
LAST_MIGRATION_FILE=$(bin/rake db:migrate:status 2>/dev/null | tail -n 2 | head -1 | awk '{print $3$4$5$6}') | |
if [[ $LAST_MIGRATION_FILE == "**********NOFILE**********" ]] | |
then | |
echo -en "\\033[1;31mMaybe you need to get back to the previous branch and rollback some migrations?\\033[0;39m\n" | |
else | |
echo -en "\\033[32mMigrations are OK!\\033[0;39m\n" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment