fix: scripts
This commit is contained in:
parent
9c52b0b7b9
commit
b9dcc2d05b
@ -1 +1 @@
|
||||
Subproject commit 3b3eae9b02e25ae9077d5f5e0c63cf694b896e58
|
||||
Subproject commit 0a4957d48c308b224c107506cf0bd88f1c32b0cd
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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}"
|
||||
|
Loading…
Reference in New Issue
Block a user