diff options
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 |