Mercurial > public > ssdt-docker
annotate postgres/setupDatabase.sh @ 511:9ba85a0aa135
USASR-5154 use alpine
author | belknapSSDT <zach.belknap@mcoecn.org> |
---|---|
date | Fri, 29 Sep 2023 13:02:52 -0400 |
parents | 53671513b240 |
children |
rev | line source |
---|---|
3 | 1 #!/bin/bash |
2 | |
3 export PGUSER=postgres | |
81
53671513b240
DEP-10: add timezone and locale settings. add java base image. add native APR for tomcat
smith@nwoca.org
parents:
3
diff
changeset
|
4 result=`psql -t -A <<- EOSQL |
3 | 5 SELECT 1 FROM pg_database WHERE datname='$DB_NAME'; |
6 EOSQL` | |
7 | |
81
53671513b240
DEP-10: add timezone and locale settings. add java base image. add native APR for tomcat
smith@nwoca.org
parents:
3
diff
changeset
|
8 echo "checking for existing $DB_NAME ( $result ) " |
53671513b240
DEP-10: add timezone and locale settings. add java base image. add native APR for tomcat
smith@nwoca.org
parents:
3
diff
changeset
|
9 |
53671513b240
DEP-10: add timezone and locale settings. add java base image. add native APR for tomcat
smith@nwoca.org
parents:
3
diff
changeset
|
10 if [[ $result == "1" ]]; then |
3 | 11 echo "$DB_NAME exists. continuing startup." |
12 # database exists | |
13 # $? is 0 | |
14 exit 0 | |
15 else | |
16 echo "Creating $DB_NAME for $DB_USER" | |
17 psql <<- EOSQL | |
18 CREATE ROLE $DB_USER WITH LOGIN ENCRYPTED PASSWORD '${DB_PASS}' CREATEDB; | |
19 CREATE DATABASE $DB_NAME WITH OWNER $DB_USER TEMPLATE template0 ENCODING 'UTF8'; | |
20 GRANT ALL PRIVILEGES ON DATABASE $DB_NAME TO $DB_USER; | |
21 EOSQL | |
22 fi | |
23 | |
24 echo "" | |
25 echo "$DB_NAME database created" |