From 2b309097ca145651618234476160fb30405eabe7 Mon Sep 17 00:00:00 2001 From: Linnnus Date: Mon, 17 Feb 2025 20:28:59 +0100 Subject: Initial commit --- db/create_db.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 db/create_db.sh (limited to 'db/create_db.sh') diff --git a/db/create_db.sh b/db/create_db.sh new file mode 100755 index 0000000..adbc245 --- /dev/null +++ b/db/create_db.sh @@ -0,0 +1,22 @@ +set -e -u -x + +if [ -e "$1" ]; then + echo "Database \"$1\" already exists. Doing nothing." + exit 0 +fi + +mkdir --parent -- "$1" + +# Create database cluster +initdb --auth-local=trust --username=postgres -- "$1" + +# Start DB for next operation... +pg_ctl -D "$1" start +trap 'pg_ctl -D "$1" stop' EXIT + +# Create a database within said cluster called 'testdb'. +# TODO: We should restore a "backup" which contains the initial state for testing (i.e. with assignments and existing users). +createdb --username=postgres --no-password --echo testdb "Default database for testing". + +# Load DB dump +psql --username=postgres --dbname=testdb <./db/dump.sql -- cgit v1.2.3