comparison db_schema/setup-db.sh @ 934:4d8b8c849935

A bit of cleanup.
author Tom Gottfried <tom@intevation.de>
date Fri, 06 May 2016 12:22:13 +0200
parents 56d2dd058906
children bc44dcda6f69
comparison
equal deleted inserted replaced
933:56d2dd058906 934:4d8b8c849935
1 #!/bin/sh -e 1 #!/bin/sh -e
2 # SYNOPSIS 2 # SYNOPSIS
3 # ./setup-db.sh [-c] [ROLE_NAME] [ROLE_PW] [DB_NAME] 3 # ./setup-db.sh [-c] [ROLE_NAME] [ROLE_PW] [DB_NAME]
4 # -c clean - drop an existing database 4 # -c clean - drop an existing database
5 # ROLE_NAME nema of db user (default = lada) 5 # ROLE_NAME name of db user (default = lada)
6 # ROLE_PW login password (default = ROLE_NAME) 6 # ROLE_PW login password (default = ROLE_NAME)
7 # DB_NAME name of the databaes (default = ROLE_NAME) 7 # DB_NAME name of the databaes (default = ROLE_NAME)
8 # 8 #
9 # There will be used a remote database server if there exists the enviroment variable DB_SRV 9 # There will be used a remote database server if there exists the
10 # and optional DB_PORT 10 # enviroment variable DB_SRV and optional DB_PORT
11 11
12 DIR=`dirname $0` 12 DIR=`dirname $0`
13 13
14 while getopts "c" opt; do 14 while getopts "c" opt; do
15 case "$opt" in 15 case "$opt" in
20 done 20 done
21 21
22 shift $((OPTIND-1)) 22 shift $((OPTIND-1))
23 23
24 ROLE_NAME=${1:-lada} 24 ROLE_NAME=${1:-lada}
25 echo "DROLE_NAME = $ROLE_NAME" 25 echo "ROLE_NAME = $ROLE_NAME"
26 ROLE_PW=${2:-$ROLE_NAME} 26 ROLE_PW=${2:-$ROLE_NAME}
27 echo "ROLE_PW = $ROLE_PW" 27 echo "ROLE_PW = $ROLE_PW"
28 DB_NAME=${3:-$ROLE_NAME} 28 DB_NAME=${3:-$ROLE_NAME}
29 echo "DB_NAME = $DB_NAME" 29 echo "DB_NAME = $DB_NAME"
30 30
31 # if variable DB_SRV and otional DB_PORT is set a remote database connection will be used 31 # if variable DB_SRV and otional DB_PORT is set a remote database connection will be used
32 if [ -n "$DB_SRV" ] ; then DB_CONNECT_STRING="-h $DB_SRV" ; fi 32 if [ -n "$DB_SRV" ] ; then DB_CONNECT_STRING="-h $DB_SRV" ; fi
33 if [ -n "$DB_SRV" -a -n "$DB_PORT" ] ; then 33 if [ -n "$DB_SRV" -a -n "$DB_PORT" ] ; then
34 DB_CONNECT_STRING="$DB_CONNECT_STRING -p $DB_PORT" 34 DB_CONNECT_STRING="$DB_CONNECT_STRING -p $DB_PORT"
35 fi 35 fi
36 DB_CONNECT_STRING="$DB_CONNECT_STRING -U postgres" 36 DB_CONNECT_STRING="$DB_CONNECT_STRING -U postgres"
37 echo "DB_CONNECT_STRING = $DB_CONNECT_STRING" 37 echo "DB_CONNECT_STRING = $DB_CONNECT_STRING"
38 38
48 48
49 echo create db $DB_NAME 49 echo create db $DB_NAME
50 psql $DB_CONNECT_STRING --command \ 50 psql $DB_CONNECT_STRING --command \
51 "CREATE DATABASE $DB_NAME WITH OWNER = $ROLE_NAME ENCODING = 'UTF8'" 51 "CREATE DATABASE $DB_NAME WITH OWNER = $ROLE_NAME ENCODING = 'UTF8'"
52 52
53 echo create postgis extention 53 echo create postgis extension
54 psql $DB_CONNECT_STRING -d $DB_NAME --command \ 54 psql $DB_CONNECT_STRING -d $DB_NAME --command \
55 "CREATE EXTENSION IF NOT EXISTS postgis WITH SCHEMA public" 55 "CREATE EXTENSION IF NOT EXISTS postgis WITH SCHEMA public"
56 56
57 echo create stammdaten schema 57 echo create stammdaten schema
58 psql $DB_CONNECT_STRING -d $DB_NAME -f $DIR/stammdaten_schema.sql 58 psql $DB_CONNECT_STRING -d $DB_NAME -f $DIR/stammdaten_schema.sql
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)