annotate postgres/setupDatabase.sh @ 401:8bbf03e60259 release/v2.13.0

INV-197 merge release/v2.13.0 into default
author Matt Calmes <calmes@ssdt-ohio.org>
date Thu, 28 Oct 2021 08:05:06 -0400
parents 53671513b240
children
rev   line source
3
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
1 #!/bin/bash
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
2
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
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
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
5 SELECT 1 FROM pg_database WHERE datname='$DB_NAME';
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
6 EOSQL`
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
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
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
11 echo "$DB_NAME exists. continuing startup."
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
12 # database exists
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
13 # $? is 0
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
14 exit 0
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
15 else
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
16 echo "Creating $DB_NAME for $DB_USER"
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
17 psql <<- EOSQL
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
18 CREATE ROLE $DB_USER WITH LOGIN ENCRYPTED PASSWORD '${DB_PASS}' CREATEDB;
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
19 CREATE DATABASE $DB_NAME WITH OWNER $DB_USER TEMPLATE template0 ENCODING 'UTF8';
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
20 GRANT ALL PRIVILEGES ON DATABASE $DB_NAME TO $DB_USER;
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
21 EOSQL
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
22 fi
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
23
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
24 echo ""
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
25 echo "$DB_NAME database created"