Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save davehughes/c115a7adbb6bd9f99945 to your computer and use it in GitHub Desktop.
Save davehughes/c115a7adbb6bd9f99945 to your computer and use it in GitHub Desktop.
Detect duplicate indices in South migrations between two git commits
RETURN_CODE=0
MIGS_PATH="thefundersclub/migrations"
# List the IDs of any migrations added since the previous commit
NEW_MIGS=$(git log --name-status $GIT_PREVIOUS_COMMIT..$GIT_COMMIT -- $MIGS_PATH | egrep 'A\tthefundersclub/migrations' | cut -f 2 | xargs basename | cut -d_ -f 1)
echo "Checking new migrations for duplication: $NEW_MIGS"
# List the last N migration IDs
EXISTING_MIGS=$(git ls-tree -r $GIT_PREVIOUS_COMMIT | grep $MIGS_PATH | cut -d" " -f 3 | cut -f 2 | xargs basename | cut -d_ -f 1 | sort | tail -n 20)
echo "Existing migs: " $EXISTING_MIGS
MERGED_MIGS=$(echo $NEW_MIGS $EXISTING_MIGS | tr -s " " "\n" | sort)
echo "Merged migs: " $MERGED_MIGS
DUPES=$(printf "$MERGED_MIGS" | uniq -d)
if [[ $DUPES != "" ]]; then
echo "Found duplicate migration(s): $DUPES"
RETURN_CODE=1
fi
exit $RETURN_CODE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment