Mercurial > lada > lada-server
comparison db_schema/setup-db.sh @ 930:d3d9cd5e18f8
add initialze sequences in lada_data.sql
author | Michael Stanko <mstanko@bfs.de> |
---|---|
date | Wed, 04 May 2016 16:00:41 +0200 |
parents | 6ab17d8b5558 |
children | 77ab53348966 |
comparison
equal
deleted
inserted
replaced
929:18197a04b713 | 930:d3d9cd5e18f8 |
---|---|
1 #!/bin/sh | 1 #!/bin/sh -x |
2 # SYNOPSIS | |
3 # ./setup-db.sh [-c] [ROLE_NAME] [ROLE_PW] [DB_NAME] | |
4 # -c clean - drop an existing database | |
5 # ROLE_NAME nema of db user (default = lada) | |
6 # ROLE_PW login password (default = ROLE_NAME) | |
7 # DB_NAME name of the databaes (default = ROLE_NAME) | |
8 # | |
9 # There will be used a remote database server if there exists the enviroment variable DB_SRV | |
10 # and optional DB_PORT | |
11 | |
2 DIR=`dirname $0` | 12 DIR=`dirname $0` |
13 | |
14 if [ " $1" == " -c" ] ; then | |
15 DROP_DB="true" | |
16 shift | |
17 fi | |
3 | 18 |
4 ROLE_NAME=${1:-lada} | 19 ROLE_NAME=${1:-lada} |
5 echo "DROLE_NAME = $ROLE_NAME" | 20 echo "DROLE_NAME = $ROLE_NAME" |
6 ROLE_PW=${2:-$ROLE_NAME} | 21 ROLE_PW=${2:-$ROLE_NAME} |
7 echo "ROLE_PW = $ROLE_PW" | 22 echo "ROLE_PW = $ROLE_PW" |
19 if [ `psql $DB_CONNECT_STRING -t --command "SELECT count(*) FROM pg_catalog.pg_user WHERE usename = '$ROLE_NAME'"` -eq 0 ] ; then | 34 if [ `psql $DB_CONNECT_STRING -t --command "SELECT count(*) FROM pg_catalog.pg_user WHERE usename = '$ROLE_NAME'"` -eq 0 ] ; then |
20 echo create user $ROLE_NAME | 35 echo create user $ROLE_NAME |
21 psql $DB_CONNECT_STRING --command "CREATE USER $ROLE_NAME PASSWORD '$ROLE_PW';" | 36 psql $DB_CONNECT_STRING --command "CREATE USER $ROLE_NAME PASSWORD '$ROLE_PW';" |
22 fi | 37 fi |
23 | 38 |
24 if psql -h test-pgsql1-fr.lab.bfs.de -U postgres -l | grep -q "^ $DB_NAME " ; then | 39 if [ "$DROP_DB" == "true" ] && psql $DB_CONNECT_STRING -l | grep -q "^ $DB_NAME " ; then |
25 echo drop db $DB_NAME | 40 echo drop db $DB_NAME |
26 psql $DB_CONNECT_STRING --command "DROP DATABASE $DB_NAME" | 41 psql $DB_CONNECT_STRING --command "DROP DATABASE $DB_NAME" |
27 fi | 42 fi |
28 | 43 |
29 echo create db $DB_NAME | 44 echo create db $DB_NAME |