db/scripts/diff.sh
Orion Kindel 1bf3d29863
All checks were successful
migrate-devel / migrate-devel (push) Successful in 7s
migrate-stage / migrate-stage (push) Successful in 7s
fix: diff broken?
2023-07-14 23:09:14 -04:00

38 lines
870 B
Bash
Executable File

#! /bin/bash
set -e
source ./scripts/env.sh ./.env.schema
rev=$(echo "$1" | xargs)
head=$(git show --format=format:%h -q | xargs)
migration="./migrations/${rev}_to_${head}.sql"
head_url=postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:5432/dnim
base_url=postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:5433/dnim
if [[ -z "$rev" ]]; then
echo "revision to diff is required" 1>&2;
exit 1;
fi
docker compose up -d 1>&2
rm -r ./migrations || true
git fetch --all 1>&2
git restore ./migrations --source origin/manual_migrations 1>&2
if [[ ! -f "$migration" ]]; then
./scripts/build.sh "$rev" 1>&2
./scripts/build.sh HEAD 1>&2
echo "migrate from $rev => HEAD" 1>&2
migra --unsafe $base_url $head_url > "$migration" \
|| echo "migra exited with code $?. this is /probably/ fine" 1>&2
fi
echo "$migration"
docker compose down 1>&2