From 05271f5ecbd77e05f03354648bfb364428067aef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakobus=20Sch=C3=BCrz?= Date: Tue, 30 May 2023 17:20:17 +0200 Subject: [PATCH] add database-functions --- functions.sh | 66 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 59 insertions(+), 7 deletions(-) diff --git a/functions.sh b/functions.sh index 87d1b58..35ce6d3 100755 --- a/functions.sh +++ b/functions.sh @@ -1252,6 +1252,33 @@ function getdbcreds_cnf () { } +function connectdbpostgres () { + + case $HOSTNAME in + *jra*|*jira*) + getdbcreds_jra $2 + ;; + *cnf*|*confapp*) + getdbcreds_cnf $2 + ;; + *) + echo "wrong argument" + return 1 + ;; + esac + + DB_USER=postgres + read -p "Password for user ${DB_USER} on ${DB_HOST}: " DB_PWD + + cat << EOF + connect to ${DB_HOST}:${DB_PORT} + with user: ${DB_USER} + and passwd: ${DB_PWD} +EOF + + PGPASSWORD=$DB_PWD psql -h $DB_HOST -p $DB_PORT -U postgres +} + function connectdb () { case $HOSTNAME in @@ -1261,13 +1288,6 @@ function connectdb () { *cnf*|*confapp*) getdbcreds_cnf $2 ;; -# case $1 in -# jra|jira) -# getdbcreds_jra $2 -# ;; -# cnf|conf|confluence) -# getdbcreds_cnf $2 -# ;; *) echo "wrong argument" return 1 @@ -1424,5 +1444,37 @@ setgitremote() { git submodule sync git submodule update --init --recursive --remote } + +pg_drop_and_recreate_db () { + DB=$1 + DBHOST=localhost + case ${DB} in + jra*) + PORT=5532 + ;; + cnf*) + PORT=5432 + ;; + *) + return 1 + ;; + esac + # DROP and recreate adatabase in PG12 jira + psql -h$DBHOST -p $PORT -U postgres + \c postgres + DROP DATABASE ${DB}; + CREATE DATABASE ${DB} OWNER ${DB}; + REVOKE CONNECT,TEMPORARY ON DATABASE ${DB} FROM PUBLIC; + \c ${DB} + REVOKE ALL ON SCHEMA public FROM ${DB}; + REVOKE ALL ON SCHEMA public FROM public; + ALTER SCHEMA public OWNER TO ${DB}; + GRANT ALL ON SCHEMA public TO ${DB}; + \dn+ + \l+ ${DB} + \c postgres +} #EOF + +