From 6b525b388a63e276c333189a76f5c0ceae73019e Mon Sep 17 00:00:00 2001 From: Mathilde Ffrench Date: Wed, 21 Nov 2018 18:59:20 +0100 Subject: [PATCH 1/2] enable db conf for simplified docker-compose --- app/persistence/postgreSQL/db/createdb.sh | 74 ++++++++++++++--------- 1 file changed, 46 insertions(+), 28 deletions(-) diff --git a/app/persistence/postgreSQL/db/createdb.sh b/app/persistence/postgreSQL/db/createdb.sh index 7163528c0..06364f489 100755 --- a/app/persistence/postgreSQL/db/createdb.sh +++ b/app/persistence/postgreSQL/db/createdb.sh @@ -1,32 +1,50 @@ #!/usr/bin/env bash -if [[ -z "${DATABASE_USERNAME}" ]]; then - USER=$( jq .pg.username pgconfig.json ) -else - USER=$DATABASE_USERNAME -fi -if [[ -z "${DATABASE_DATABASE}" ]]; then - DATABASE=$( jq .pg.database pgconfig.json ) -else - DATABASE=$DATABASE_DATABASE -fi -if [[ -z "${DATABASE_PASSWORD}" ]]; then - PASSWD=$(jq .pg.passwd pgconfig.json | sed "y/\"/'/") -else - PASSWD=$DATABASE_PASSWORD -fi +## IF ALREADY CONFIGURED NO NEED TO RECONFIG +if [ ! -f /${PGDATA}/conf.done ]; then + + if [[ -z "${DATABASE_USERNAME}" ]]; then + USER=$( jq .pg.username pgconfig.json ) + else + USER=$DATABASE_USERNAME + fi + if [[ -z "${DATABASE_DATABASE}" ]]; then + DATABASE=$( jq .pg.database pgconfig.json ) + else + DATABASE=$DATABASE_DATABASE + fi + if [[ -z "${DATABASE_PASSWORD}" ]]; then + PASSWD=$(jq .pg.passwd pgconfig.json | sed "y/\"/'/") + else + PASSWD=$DATABASE_PASSWORD + fi -echo "USER=${USER}" -echo "DATABASE=${DATABASE}" -echo "PASSWD=${PASSWD}" + echo "USER=${USER}" + echo "DATABASE=${DATABASE}" + echo "PASSWD=${PASSWD}" -case $OSTYPE in - darwin*) echo "Creating Default user $USER..." ; - psql -U postgres -c "CREATE USER $USER WITH PASSWORD '$PASSWD'" ; - psql postgres -v dbname=$DATABASE -v user=$USER -v passwd=$PASSWD -f ./explorerpg.sql ; - psql postgres -v dbname=$DATABASE -v user=$USER -v passwd=$PASSWD -f ./updatepg.sql ;; - linux*) echo "Creating Default user..." ; - sudo -u postgres psql -U postgres -c "CREATE USER $USER WITH PASSWORD '$PASSWD'" ; - sudo -u postgres psql -v dbname=$DATABASE -v user=$USER -v passwd=$PASSWD -f ./explorerpg.sql ; - sudo -u postgres psql -v dbname=$DATABASE -v user=$USER -v passwd=$PASSWD -f ./updatepg.sql ;; -esac \ No newline at end of file + case $OSTYPE in + darwin*) + echo "Creating Default user $USER..." ; + psql -U postgres -c "CREATE USER $USER WITH PASSWORD '$PASSWD'" ; + psql postgres -v dbname=$DATABASE -v user=$USER -v passwd=$PASSWD -f ./explorerpg.sql ; + psql postgres -v dbname=$DATABASE -v user=$USER -v passwd=$PASSWD -f ./updatepg.sql ;; + + linux*) + WHOAMI=`whoami` + if [ "${WHOAMI}" != "postgres" ]; then + echo "Creating Default user..." ; + sudo -u postgres psql -U postgres -c "CREATE USER $USER WITH PASSWORD '$PASSWD'" ; + sudo -u postgres psql -v dbname=$DATABASE -v user=$USER -v passwd=$PASSWD -f ./explorerpg.sql ; + sudo -u postgres psql -v dbname=$DATABASE -v user=$USER -v passwd=$PASSWD -f ./updatepg.sql + else + echo "Creating Default user..." ; + psql -U postgres -c "CREATE USER $USER WITH PASSWORD '$PASSWD'" ; + psql -v dbname=$DATABASE -v user=$USER -v passwd=$PASSWD -f ./explorerpg.sql ; + psql -v dbname=$DATABASE -v user=$USER -v passwd=$PASSWD -f ./updatepg.sql + fi + ;; + esac + + touch /${PGDATA}/conf.done +fi From 53e9d9d6e8419b06a5fc395acf48ade7a810dd54 Mon Sep 17 00:00:00 2001 From: Mathilde Ffrench Date: Wed, 21 Nov 2018 18:59:37 +0100 Subject: [PATCH 2/2] remove faulty sql --- app/persistence/postgreSQL/db/explorerpg.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/persistence/postgreSQL/db/explorerpg.sql b/app/persistence/postgreSQL/db/explorerpg.sql index 7c3d1b017..e6deb9518 100644 --- a/app/persistence/postgreSQL/db/explorerpg.sql +++ b/app/persistence/postgreSQL/db/explorerpg.sql @@ -2,7 +2,7 @@ -- SPDX-License-Identifier: Apache-2.0 -- -CREATE USER :user WITH PASSWORD :passwd; +-- CREATE USER :user WITH PASSWORD :passwd; DROP DATABASE IF EXISTS :dbname; CREATE DATABASE :dbname owner :user; \c :dbname;