-
-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
61ac912
commit 574b4e5
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env bash | ||
|
||
# https://gist.github.com/vncsna/64825d5609c146e80de8b1fd623011ca | ||
# Note we're not using `x` because it's noisy. If you want to use it for debugging, uncomment the line below. | ||
set -euo pipefail | ||
#set -x | ||
|
||
bundle exec rails db:migrate | ||
GIT_STATUS=`git status db/schema.rb` | ||
|
||
if [[ $GIT_STATUS =~ "nothing to commit, working tree clean" ]]; then | ||
exit 0 | ||
else | ||
# We don't want the git/grep/grep command below to fail this script so we temporarily `set +e` | ||
set +e | ||
`git diff db/schema.rb | grep "^+[^+]" | grep -v "ActiveRecord::Schema\["` | ||
STATUS_CODE=$? | ||
# Now that we've run the git/grep/grep command and captured it's status code we can `set -e` again | ||
set -e | ||
|
||
if [[ $STATUS_CODE == 1 ]] ; then | ||
echo "Rails version was updated, but there were no changes to any tables." | ||
exit 0 | ||
fi | ||
|
||
echo "" | ||
echo "rails db:migrate made a change to your database's schema." | ||
echo "Please make sure your database is updated locally before pushing to CircleCI:" | ||
git diff db/schema.rb | ||
exit 1 | ||
fi |