40 lines
776 B
Bash
Executable File
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
|