db/scripts/diff.sh
Orion Kindel 9929ee928a
Some checks failed
gen-migrations / gen-migrations (push) Failing after 8s
fix: gen-migrations workflow
2023-07-19 18:46:33 -05:00

38 lines
1.0 KiB
Bash
Executable File

#! /bin/bash
set -e
source ./scripts/env.sh ./.env.schema
base="$1"
head_arg="$2"
head=$(git show --format=format:%h -q | xargs)
if [[ -n "$head_arg" ]]; then
head="$head_arg"
fi;
migration="./migrations/${base}_to_${head}.sql"
pg_host_base=${PG_HOST_BASE:-localhost:5432}
pg_host_head=${PG_HOST_HEAD:-localhost:5433}
base_url="postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@$pg_host_base/dnim"
head_url="postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@$pg_host_head/dnim"
if [[ -z "$base" ]] || [[ -z "$head" ]]; then
echo "revisions to diff are required ex. ./scripts/diff.sh abc bcd" 1>&2;
exit 1;
fi
if [[ ! -f "$migration" ]]; then
./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)
until pg_isready -p 5432 1>/dev/null && pg_isready -p 5433 1>/dev/null; do true; done;
migra --unsafe "$base_url" "$head_url" || echo "migra exited with code $?. this is /probably/ fine" 1>&2
else
cat "$migration"
fi