38 lines
870 B
Bash
Executable File
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
|