#! /usr/bin/bash source ./scripts/env.sh 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/$POSTGRES_DB psql \ --quiet \ $url \ --command="drop schema public cascade; create schema public;" \ 1>/dev/null ls ./schema/ | xargs -I{} \ psql \ --quiet \ $url \ --file=./schema/{} \ 1>/dev/null