db/scripts/build.sh
Orion Kindel 0b9c597ca4
Some checks failed
migrate-devel / migrate-devel (push) Failing after 7s
migrate-stage / migrate-stage (push) Successful in 5s
chore: fix ci
2023-06-28 11:27:14 -05:00

42 lines
777 B
Bash
Executable File

#! /bin/bash
set -ex
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 --quiet --hard "$rev"
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/dnim" \
--file=./schema/{} \
1>/dev/null