From 574b4e52a04ae8304d65bafb1cb6560ed5006a86 Mon Sep 17 00:00:00 2001 From: Jeremy Green Date: Wed, 20 Nov 2024 16:36:43 -0600 Subject: [PATCH] Oops, we still need this --- .circleci/db_schema_check | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 .circleci/db_schema_check diff --git a/.circleci/db_schema_check b/.circleci/db_schema_check new file mode 100755 index 000000000..53ce24211 --- /dev/null +++ b/.circleci/db_schema_check @@ -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