2023-06-18 15:52:44 +00:00
|
|
|
#! /bin/bash
|
2023-06-09 01:29:13 +00:00
|
|
|
|
2023-07-20 17:48:07 +00:00
|
|
|
set -xe
|
2023-06-09 01:29:13 +00:00
|
|
|
|
2023-07-20 18:03:07 +00:00
|
|
|
source ./scripts/common.sh
|
2023-06-11 21:43:53 +00:00
|
|
|
source ./scripts/env.sh ./.env.schema
|
2023-06-09 01:29:13 +00:00
|
|
|
|
2023-07-17 03:47:16 +00:00
|
|
|
base="$1"
|
|
|
|
head_arg="$2"
|
2023-07-03 00:40:19 +00:00
|
|
|
head=$(git show --format=format:%h -q | xargs)
|
2023-07-16 02:36:32 +00:00
|
|
|
|
|
|
|
if [[ -n "$head_arg" ]]; then
|
|
|
|
head="$head_arg"
|
|
|
|
fi;
|
|
|
|
|
2023-07-17 03:47:16 +00:00
|
|
|
migration="./migrations/${base}_to_${head}.sql"
|
2023-06-09 01:29:13 +00:00
|
|
|
|
2023-07-20 00:03:48 +00:00
|
|
|
db() {
|
2023-07-20 17:48:07 +00:00
|
|
|
echo -n "postgresql+pg8000:///dnim?port=$1&user=$POSTGRES_USER&password=$POSTGRES_PASSWORD"
|
2023-07-20 00:03:48 +00:00
|
|
|
}
|
2023-07-17 03:47:16 +00:00
|
|
|
|
2023-07-17 19:44:40 +00:00
|
|
|
if [[ -z "$base" ]] || [[ -z "$head" ]]; then
|
2023-07-17 03:47:16 +00:00
|
|
|
echo "revisions to diff are required ex. ./scripts/diff.sh abc bcd" 1>&2;
|
2023-06-09 01:29:13 +00:00
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
|
2023-07-20 17:48:07 +00:00
|
|
|
set +e
|
2023-07-20 18:03:07 +00:00
|
|
|
if schema_changed "$base" "$head"; then
|
2023-07-20 17:00:43 +00:00
|
|
|
echo ""
|
|
|
|
exit 0;
|
|
|
|
fi;
|
2023-07-20 18:03:07 +00:00
|
|
|
set -e
|
2023-07-20 17:00:43 +00:00
|
|
|
|
2023-07-03 00:40:19 +00:00
|
|
|
if [[ ! -f "$migration" ]]; then
|
2023-07-19 02:31:56 +00:00
|
|
|
./scripts/build.sh base "$base" 1>&2 || (echo "base failed to build" && exit 1)
|
|
|
|
./scripts/build.sh head "$head" 1>&2 || (echo "head failed to build" && exit 1)
|
2023-06-27 23:43:04 +00:00
|
|
|
|
2023-07-20 17:00:43 +00:00
|
|
|
until pg_isready --quiet -p 5432 && pg_isready --quiet -p 5433; do true; done;
|
|
|
|
|
2023-07-20 00:09:20 +00:00
|
|
|
migra --unsafe "$(db 5432)" "$(db 5433)" || echo "migra exited with code $?. this is /probably/ fine" 1>&2
|
2023-07-19 02:31:56 +00:00
|
|
|
else
|
|
|
|
cat "$migration"
|
2023-07-03 00:40:19 +00:00
|
|
|
fi
|