summaryrefslogtreecommitdiff
path: root/db/create_db.sh
blob: adbc24596a867c4f61070b37de81114e0928645c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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