diff --git a/migrations b/migrations index 3b3eae9..0a4957d 160000 --- a/migrations +++ b/migrations @@ -1 +1 @@ -Subproject commit 3b3eae9b02e25ae9077d5f5e0c63cf694b896e58 +Subproject commit 0a4957d48c308b224c107506cf0bd88f1c32b0cd diff --git a/scripts/common.sh b/scripts/common.sh index 9ccd839..379acd1 100644 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -7,3 +7,21 @@ query_file() { query() { psql -v ON_ERROR_STOP=1 --single-transaction --quiet "$1" --command="$2" 1>&2 } + +schema_changed() { + base="$1" + head="$2" + if [[ -z "$head" ]]; then + base="$1~" + head="$1" + fi + + schema_changed=$(git diff --quiet "$base" "$head" -- ./schema) + schema_changed_exit=$? + + if [[ "$schema_changed_exit" = "1" ]]; then + exit 0 + else + exit 1 + fi +} diff --git a/scripts/diff.sh b/scripts/diff.sh index 9d8bb80..acbc3ff 100755 --- a/scripts/diff.sh +++ b/scripts/diff.sh @@ -2,6 +2,7 @@ set -xe +source ./scripts/common.sh source ./scripts/env.sh ./.env.schema base="$1" @@ -24,13 +25,11 @@ if [[ -z "$base" ]] || [[ -z "$head" ]]; then fi set +e -schema_changed=$(git diff --quiet "$base" "$head" -- ./schema) -schema_changed_exit=$? -set -e -if [[ "$schema_changed_exit" = "0" ]]; then +if schema_changed "$base" "$head"; then echo "" exit 0; fi; +set -e if [[ ! -f "$migration" ]]; then ./scripts/build.sh base "$base" 1>&2 || (echo "base failed to build" && exit 1) diff --git a/scripts/migrate.sh b/scripts/migrate.sh index fe64dcb..7ba4b27 100755 --- a/scripts/migrate.sh +++ b/scripts/migrate.sh @@ -8,7 +8,7 @@ source ./scripts/env.sh ./.env get_dnim_database_count="copy (select count(*) from pg_database where datname = 'dnim') to stdout with null as '';" dnim_database_count=$(query "$POSTGRES_URI/postgres" "$get_dnim_database_count" 2>&1) -git submodule update --init migrations +git submodule update --init --remote migrations if [[ "$dnim_database_count" = "0" ]]; then echo "fresh database" @@ -49,6 +49,9 @@ else if [[ -f "./migrations/${base}_skipped.sql" ]]; then echo "${base} (skipped)" continue + elif ! (schema_changed "$base"); then + echo "${base} (skipped, no changes to schema)" + continue elif [[ -f "./migrations/$mig" ]]; then head=$(echo $mig | awk -F'[_.]' '{print $3}') echo "${base} -> ${head}"