diff options
author | Linnnus <[email protected]> | 2025-02-17 20:28:59 +0100 |
---|---|---|
committer | Linnnus <[email protected]> | 2025-02-17 20:28:59 +0100 |
commit | 2b309097ca145651618234476160fb30405eabe7 (patch) | |
tree | 20321cf83d18c0c3c3a0a745626565074ea69a41 /db/create_db.sh |
Initial commit
Diffstat (limited to 'db/create_db.sh')
-rwxr-xr-x | db/create_db.sh | 22 |
1 files changed, 22 insertions, 0 deletions
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 |