Created
October 3, 2019 22:53
-
-
Save tennox/1007bc16bada1272be9c426941c45fe6 to your computer and use it in GitHub Desktop.
Reset and initialize Meteor DB on a git ref and start the app again afterwards
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
#!/bin/bash | |
set -e | |
################################################# | |
if [[ $# -ne 1 ]]; then | |
echo "This script:" | |
echo "1. resets and initializes the DB on the specified commit/branch" | |
echo "2. goes back to the codebase you ran this script from" | |
echo "3. runs the app again" | |
echo | |
echo "Usage:" | |
echo "test-migration-against-ref.sh <ref>" | |
echo " ref - branch or commit sha that we reset the DB on" | |
echo | |
echo "Example:" | |
echo " test-migration-against-ref.sh master" | |
exit 0 | |
fi | |
################################################# | |
WAIT_STRING="Started your app" | |
GIT_POS=$(git rev-parse --abbrev-ref HEAD) | |
DID_STASH=false | |
if ! git diff-index --quiet HEAD --; then | |
echo -e "[-] Stashing uncommitted changes" | |
git stash save --include-untracked "test-migration starting point" | |
DID_STASH=true | |
fi | |
if [[ -z $1 ]]; then | |
echo -e "\n[-] First argument should be a ref (branch name / commit sha) that I should revert to for resetting the DB." >&2 | |
exit 1 | |
fi | |
echo -e "\n[-] Reverting to $1" | |
git checkout $1 | |
echo -e "\n[-] Resetting DB" | |
meteor reset | |
echo -e "\n[-] Running app to set up initial DB" | |
# run and wait for WAIT_STRING | |
# https://superuser.com/a/1302819 | |
{ meteor run --once --settings=settings/development.json & echo $! > test-migration-run.pid; } \ | |
| tee test-migration-run1.log \ | |
| { grep -m1 "$WAIT_STRING" && kill -9 "$(cat test-migration-run.pid)" && rm test-migration-run.pid ; } | |
echo -e "\n[-] Going again to $GIT_POS (position before running this script)" | |
git checkout "$GIT_POS" | |
if $DID_STASH; then | |
echo -e "\n[-] Re-applying stashed changes" | |
git stash pop stash@{0} | |
fi | |
echo -e "\n[-] Running app again (to check migration)" | |
# run and wait for WAIT_STRING | |
{ meteor run --once --settings=settings/development.json & echo $! > test-migration-run.pid; } \ | |
| tee test-migration-run2.log \ | |
| { grep -m1 "Server startup complete!" && kill -9 "$(cat test-migration-run.pid)" && rm test-migration-run.pid ; } | |
less -R +G test-migration-run2.log | |
rm test-migration-run*.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment