Move with-db.sh to scripts

This commit is contained in:
2025-08-09 17:39:12 +02:00
parent bb66615c7f
commit e089251c2f
+23
View File
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
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
"$@"