Skip to content

Instantly share code, notes, and snippets.

@mortenson
Last active January 4, 2024 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mortenson/f1b6ef54709902f4cb3a4cef84b45899 to your computer and use it in GitHub Desktop.
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"
#! /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