diff db_schema/setup-db.sh @ 927:690b6506e0a2

merged.
author Raimund Renkert <raimund.renkert@intevation.de>
date Fri, 29 Apr 2016 16:40:26 +0200
parents 2b746f4e97d6
children 6ab17d8b5558
line wrap: on
line diff
--- a/db_schema/setup-db.sh	Fri Apr 29 16:38:33 2016 +0200
+++ b/db_schema/setup-db.sh	Fri Apr 29 16:40:26 2016 +0200
@@ -2,23 +2,55 @@
 DIR=`dirname $0`
 
 ROLE_NAME=${1:-lada}
+echo "DROLE_NAME = $ROLE_NAME="
 ROLE_PW=${2:-$ROLE_NAME}
+echo "ROLE_PW = $ROLE_PW"
 DB_NAME=${3:-$ROLE_NAME}
+echo "DB_NAME = $DB_NAME"
 
-psql --command "CREATE USER $ROLE_NAME PASSWORD '$ROLE_PW';"
-createdb -E UTF-8 $DB_NAME
+# if variable DB_SRV and otional DB_PORT is set a remote database connection will be used
+if [ -n "$DB_SRV" ] ; then DB_CONNECT_STRING="-h $DB_SRV" ; fi
+if [ -n "$DB_SRV" -a -n "$DB_PORT"  ] ; then 
+  DB_CONNECT_STRING="$DB_CONNECT_STRING -p $DB_PORT"
+fi
+DB_CONNECT_STRING="$DB_CONNECT_STRING -U postgres"
+echo "DB_CONNECT_STRING =  $DB_CONNECT_STRING"
 
-psql -d $DB_NAME  --command \
+if [ `psql $DB_CONNECT_STRING -t --command "SELECT count(*) FROM pg_catalog.pg_user WHERE usename = '$ROLE_NAME'"` -eq 0 ] ; then
+  echo create user $ROLE_NAME
+  psql $DB_CONNECT_STRING --command "CREATE USER $ROLE_NAME PASSWORD '$ROLE_PW';"
+fi
+exit
+
+if psql -h test-pgsql1-fr.lab.bfs.de -U postgres -l | grep -q "^ $DB_NAME " ; then
+  echo drop db $DB_NAME 
+  psql $DB_CONNECT_STRING --command "DROP DATABASE $DB_NAME"
+fi
+
+echo create db $DB_NAME
+psql $DB_CONNECT_STRING --command \
+     "CREATE DATABASE $DB_NAME WITH OWNER = $ROLE_NAME ENCODING = 'UTF8'"
+exit
+
+echo create postgis extention
+psql $DB_CONNECT_STRING -d $DB_NAME  --command  \
      "CREATE EXTENSION IF NOT EXISTS postgis WITH SCHEMA public"
 
-psql -d $DB_NAME -f $DIR/stammdaten_schema.sql
-psql -d $DB_NAME -f $DIR/lada_schema.sql
-psql -d $DB_NAME --command \
+echo create stammdaten schema
+psql $DB_CONNECT_STRING -d $DB_NAME -f $DIR/stammdaten_schema.sql
+
+echo create lada schema
+psql $DB_CONNECT_STRING -d $DB_NAME -f $DIR/lada_schema.sql
+echo set grants
+psql $DB_CONNECT_STRING -d $DB_NAME --command \
      "GRANT USAGE ON SCHEMA stammdaten, bund, land TO $ROLE_NAME;
       GRANT USAGE
             ON ALL SEQUENCES IN SCHEMA stammdaten, bund, land TO $ROLE_NAME;
       GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES
             ON ALL TABLES IN SCHEMA stammdaten, bund, land TO $ROLE_NAME;"
 
-psql -d $DB_NAME -f $DIR/stammdaten_data.sql
-psql -d $DB_NAME -f $DIR/lada_data.sql
+echo import stammdaten
+psql $DB_CONNECT_STRING -d $DB_NAME -f $DIR/stammdaten_data.sql
+
+echo import lada test data
+psql $DB_CONNECT_STRING -d $DB_NAME -f $DIR/lada_data.sql
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)