Mercurial > public > ssdt-docker
comparison trainingdb/setupDatabase.sh @ 90:63cb9be89a26 production v1.0.0
flow: Merged <release> 'v1.0.0' to <master> ('production').
author | smith@nwoca.org |
---|---|
date | Thu, 22 Sep 2016 01:49:20 +0100 |
parents | a5175713518c |
children |
comparison
equal
deleted
inserted
replaced
1:44f401c902ba | 90:63cb9be89a26 |
---|---|
1 #!/bin/bash | |
2 | |
3 export PGUSER=postgres | |
4 TEST=`psql <<- EOSQL | |
5 SELECT 1 FROM pg_database WHERE datname='$DB_NAME'; | |
6 EOSQL` | |
7 | |
8 if [[ $TEST == "1" ]]; then | |
9 echo "$DB_NAME exists. continuing startup." | |
10 # database exists | |
11 # $? is 0 | |
12 exit 0 | |
13 else | |
14 echo "Creating $DB_NAME for $DB_USER" | |
15 psql <<- EOSQL | |
16 CREATE ROLE $DB_USER WITH LOGIN ENCRYPTED PASSWORD '${DB_PASS}' CREATEDB; | |
17 CREATE DATABASE $DB_NAME WITH OWNER $DB_USER TEMPLATE template0 ENCODING 'UTF8'; | |
18 GRANT ALL PRIVILEGES ON DATABASE $DB_NAME TO $DB_USER; | |
19 EOSQL | |
20 | |
21 echo "Restoring backup file" | |
22 | |
23 gunzip -f $BACKUP_FILE -c | psql | |
24 | |
25 fi | |
26 | |
27 echo "" | |
28 echo "$DB_NAME database created" |