Browse Source

db drop unless prod

main
pvincent 1 month ago
parent
commit
300839d5b7
  1. 17
      scripts/db-maria
  2. 15
      scripts/db-psql

17
scripts/db-maria

@ -21,6 +21,10 @@ synopsis() {
printf "\t restore <DB_NAME> <FILE>\n" printf "\t restore <DB_NAME> <FILE>\n"
printf "\t ---------------------------\n" printf "\t ---------------------------\n"
printf "\t rename <DB_NAME> <NEW_NAME>\n" printf "\t rename <DB_NAME> <NEW_NAME>\n"
if [[ "$TARGET" != 'prod' ]]; then
printf "\t drop <DB_NAME> # unless PROD!\n"
fi
} }
list() { list() {
@ -163,10 +167,17 @@ rename() {
console "drop database \\\`$DB_NAME\\\`" console "drop database \\\`$DB_NAME\\\`"
} }
drop() {
console "drop user \\\`$DB_NAME\\\`"
console "drop database \\\`$DB_NAME\\\`"
echo "$DB_NAME dropped!"
}
# MAIN # MAIN
set -Eeuo pipefail set -Eeuo pipefail
# shellcheck source=/dev/null # shellcheck source=/dev/null
. "$MIAOU_BASEDIR/lib/functions.sh" . "$MIAOU_BASEDIR/lib/functions.sh"
TARGET=$(grep -Es "^target:" /etc/miaou/defaults.yaml | cut -d ' ' -f2)
[[ $# -lt 1 ]] && synopsis && exit 1 [[ $# -lt 1 ]] && synopsis && exit 1
ACTION=$1 ACTION=$1
@ -214,6 +225,12 @@ rename)
NEW_NAME=$3 NEW_NAME=$3
rename rename
;; ;;
drop)
[[ $# -lt 2 ]] && synopsis && exit 1
[[ "$TARGET" = 'prod' ]] && synopsis && exit 2
DB_NAME=$2
drop
;;
*) *)
synopsis synopsis
exit 1 exit 1

15
scripts/db-psql

@ -20,6 +20,9 @@ synopsis() {
printf "\t restore <DB_NAME> <FILE> [--yes]\n" printf "\t restore <DB_NAME> <FILE> [--yes]\n"
printf "\t ---------------------------\n" printf "\t ---------------------------\n"
printf "\t rename <DB_NAME> <NEW_NAME>\n" printf "\t rename <DB_NAME> <NEW_NAME>\n"
if [[ "$TARGET" != 'prod' ]]; then
printf "\t drop <DB_NAME> # unless PROD!\n"
fi
} }
list() { list() {
@ -134,11 +137,17 @@ rename() {
console "psql -c \"ALTER DATABASE \\\"$DB_NAME\\\" RENAME TO \\\"$DB_NEW_NAME\\\" \"" console "psql -c \"ALTER DATABASE \\\"$DB_NAME\\\" RENAME TO \\\"$DB_NEW_NAME\\\" \""
console "psql -c \"ALTER USER \\\"$DB_NAME\\\" RENAME TO \\\"$DB_NEW_NAME\\\" \"" console "psql -c \"ALTER USER \\\"$DB_NAME\\\" RENAME TO \\\"$DB_NEW_NAME\\\" \""
console "psql -c \"ALTER USER \\\"$DB_NEW_NAME\\\" PASSWORD '$DB_NEW_NAME' \"" console "psql -c \"ALTER USER \\\"$DB_NEW_NAME\\\" PASSWORD '$DB_NEW_NAME' \""
}
drop() {
console "dropdb $DB_NAME"
console "dropuser $DB_NAME"
echo "$DB_NAME dropped!"
} }
# MAIN # MAIN
. "$MIAOU_BASEDIR/lib/init.sh" . "$MIAOU_BASEDIR/lib/init.sh"
TARGET=$(grep -Es "^target:" /etc/miaou/defaults.yaml | cut -d ' ' -f2)
[[ $# -lt 1 ]] && synopsis && exit 1 [[ $# -lt 1 ]] && synopsis && exit 1
ACTION=$1 ACTION=$1
@ -193,6 +202,12 @@ rename)
DB_NEW_NAME=$3 DB_NEW_NAME=$3
rename rename
;; ;;
drop)
[[ $# -lt 2 ]] && synopsis && exit 1
[[ "$TARGET" = 'prod' ]] && synopsis && exit 2
DB_NAME=$2
drop
;;
*) *)
synopsis synopsis
exit 1 exit 1

Loading…
Cancel
Save