yore/with-db.sh

22 lines
461 B
Bash
Executable File

if [ -z "$BASE_DIR" ]; then
BASE_DIR=$(mktemp -d)
fi
export PGDATA="$BASE_DIR/pgdata"
# On error or exit: Stop the DB server
stop_db_server() {
pg_ctl stop -o "-p 5433" --wait
}
trap stop_db_server EXIT
if [ ! -s "$PGDATA/PG_VERSION" ]; then
initdb --username=yore-test --auth=trust || true
DO_CREATE_DB=1
fi
pg_ctl start -o "-p 5433" --wait
if [ -n "$DO_CREATE_DB" ]; then
createdb -p 5433 yore-test --username=yore-test || true
fi
"$@"