Last active
January 4, 2024 00:21
-
-
Save mortenson/f1b6ef54709902f4cb3a4cef84b45899 to your computer and use it in GitHub Desktop.
Example script that tests if migrations added in current working tree will break tests when applied to master. Good for PRs but can be used locally "safely"
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
#! /bin/bash | |
# Assumes migrations are stored in ./db/migrations as single files. | |
# Also assumes migrations are in (alphanumeric) order. | |
set -e | |
rm -rf /tmp/test-migrations | |
mkdir /tmp/test-migrations | |
cp -r db/migrations/* /tmp/test-migrations/ | |
git add . | |
git stash | |
git fetch origin master | |
git checkout master | |
git pull | |
NEW_MIGRATIONS=$(comm -23 <(ls /tmp/test-migrations | sort) <(ls db/migrations | sort)) | |
IFS=$'\n'; | |
for i in $NEW_MIGRATIONS; do | |
echo "Testing with migration $i" | |
cp /tmp/test-migrations/$i db/migrations | |
make test | |
done; | |
git reset --hard master | |
git clean -fd | |
git checkout - | |
git stash pop || true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment