db/scripts/build.sh
Orion Kindel 5da43ddf0f
All checks were successful
migrate / migrate devel (push) Successful in 1m14s
chore: add ci for migrating against devel
2023-06-18 11:25:57 -05:00

40 lines
776 B
Bash
Executable File

#! /bin/bash
source ./scripts/env.sh ./.env.schema
rev=${1:-HEAD}
if [[ -n $(git status --porcelain) ]]; then
echo "git working tree dirty" 1>&2;
exit 1;
fi
if [[ "$rev" = "HEAD" ]]; then
head=""
port=5432
else
head=$(git show --format=format:%h -q)
git reset "$rev" --quiet --hard
port=5433
fi
switch_back_to_head() {
if [[ -n "$head" ]]; then
git reset --quiet --hard "$head"
fi
}
trap 'switch_back_to_head' EXIT
url=postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:$port
dropdb=$(mktemp)
echo "drop database dnim with (force); create database dnim;" > "$dropdb"
psql --quiet "$url/postgres" --file="$dropdb" 1>/dev/null
ls ./schema/ | xargs -I{} \
psql \
--quiet \
"$url/$POSTGRES_DB" \
--file=./schema/{} \
1>/dev/null