Mercurial > lada > lada-server
diff 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 |
line wrap: on
line diff
--- a/db_schema/setup-db.sh Wed May 04 09:13:35 2016 +0200 +++ b/db_schema/setup-db.sh Wed May 04 16:00:41 2016 +0200 @@ -1,6 +1,21 @@ -#!/bin/sh +#!/bin/sh -x +# SYNOPSIS +# ./setup-db.sh [-c] [ROLE_NAME] [ROLE_PW] [DB_NAME] +# -c clean - drop an existing database +# ROLE_NAME nema of db user (default = lada) +# ROLE_PW login password (default = ROLE_NAME) +# DB_NAME name of the databaes (default = ROLE_NAME) +# +# There will be used a remote database server if there exists the enviroment variable DB_SRV +# and optional DB_PORT + DIR=`dirname $0` +if [ " $1" == " -c" ] ; then + DROP_DB="true" + shift +fi + ROLE_NAME=${1:-lada} echo "DROLE_NAME = $ROLE_NAME" ROLE_PW=${2:-$ROLE_NAME} @@ -21,7 +36,7 @@ psql $DB_CONNECT_STRING --command "CREATE USER $ROLE_NAME PASSWORD '$ROLE_PW';" fi -if psql -h test-pgsql1-fr.lab.bfs.de -U postgres -l | grep -q "^ $DB_NAME " ; then +if [ "$DROP_DB" == "true" ] && psql $DB_CONNECT_STRING -l | grep -q "^ $DB_NAME " ; then echo drop db $DB_NAME psql $DB_CONNECT_STRING --command "DROP DATABASE $DB_NAME" fi