Files
XQKqueue/scripts/init-db.sh
2026-07-12 15:53:24 +08:00

17 lines
616 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
PG_BIN="${PG_BIN:-/opt/homebrew/opt/postgresql@17/bin}"
if ! "$PG_BIN/psql" -d postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname = 'queue'" | grep -q 1; then
"$PG_BIN/psql" -d postgres -v ON_ERROR_STOP=1 -c "CREATE ROLE queue LOGIN PASSWORD 'queue'"
fi
if ! "$PG_BIN/psql" -d postgres -tAc "SELECT 1 FROM pg_database WHERE datname = 'queue'" | grep -q 1; then
"$PG_BIN/createdb" -O queue queue
fi
"$PG_BIN/psql" "postgres://queue:queue@localhost:5432/queue?sslmode=disable" -v ON_ERROR_STOP=1 -c "SELECT 1" >/dev/null
echo "PostgreSQL development database is ready."