Update with-db.sh

This commit is contained in:
Paul Brinkmeier 2025-07-28 20:59:19 +02:00
parent a24f9bcde1
commit d6a9e7156f
2 changed files with 14 additions and 5 deletions

2
.gitignore vendored
View File

@ -4,3 +4,5 @@ dist-newstyle
*.swp
result
bench.html
download
pgdata

View File

@ -1,14 +1,21 @@
BASE_DIR=$(mktemp -d)
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 --wait
pg_ctl stop -o "-p 5433" --wait
}
trap stop_db_server EXIT
initdb --username=yore-test --auth=trust
pg_ctl start --wait
createdb yore-test --username=yore-test
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
"$@"