Mercurial > public > ssdt-docker
comparison postgres/setupDatabase.sh @ 3:0cdc167e6319
DEP-2: postgres dockerfile
author | smith@nwoca.org |
---|---|
date | Sat, 12 Sep 2015 08:57:00 -0400 |
parents | |
children | 53671513b240 |
comparison
equal
deleted
inserted
replaced
2:1bf338a32172 | 3:0cdc167e6319 |
---|---|
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 fi | |
21 | |
22 echo "" | |
23 echo "$DB_NAME database created" |