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