db/scripts/build.sh

30 lines
595 B
Bash
Raw Normal View History

2023-06-09 00:38:49 +00:00
#! /usr/bin/bash
rev=${1:-HEAD}
if [[ -n $(git status --porcelain) ]]; then
echo "git working tree dirty";
exit 1;
fi
if [[ "$rev" = "HEAD" ]]; then
head=""
port=5432
else
head=$(git show --format=format:%h -q)
git reset "$rev"
port=5433
fi
while read line; do export $line; done < ./.env
url=postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:$port/$POSTGRES_DB
psql --echo-all $url --command="drop schema public cascade; create schema public;"
ls ./migrations/ | xargs -I{} psql --echo-all $url --file=./migrations/{}
if [[ -n "$head" ]]; then
git reset "$head"
fi