add database-functions

This commit is contained in:
Jakobus Schürz 2023-05-30 17:20:17 +02:00
parent 2bf3ee7a56
commit 05271f5ecb

View file

@ -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