db/scripts/diff.sh

38 lines
872 B
Bash
Raw Normal View History

#! /bin/bash
2023-06-09 01:29:13 +00:00
set -e
2023-06-09 01:29:13 +00:00
source ./scripts/env.sh ./.env.schema
2023-06-09 01:29:13 +00:00
rev=$(echo "$1" | xargs)
head=$(git show --format=format:%h -q | xargs)
migration="./migrations/${rev}_to_${head}.sql"
2023-06-09 01:29:13 +00:00
2023-06-27 23:43:04 +00:00
head_url=postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:5432/dnim
base_url=postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:5433/dnim
2023-06-09 01:29:13 +00:00
if [[ -z "$rev" ]]; then
echo "revision to diff is required" 1>&2;
2023-06-09 01:29:13 +00:00
exit 1;
fi
docker compose up -d 1>&2
2023-06-09 01:29:13 +00:00
rm -r ./migrations || true
git fetch --all 1>&2
git restore ./migrations --source origin/manual_migrations 1>&2
2023-06-09 01:29:13 +00:00
if [[ ! -f "$migration" ]]; then
2023-07-15 03:06:50 +00:00
./scripts/build.sh "$rev" 1>&2
./scripts/build.sh HEAD 1>&2
echo "migrate from $rev => HEAD" 1>&2
2023-06-27 23:43:04 +00:00
2023-07-15 03:08:37 +00:00
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