diff --git a/scripts/db-maria b/scripts/db-maria index 967ddae..1c5cb79 100755 --- a/scripts/db-maria +++ b/scripts/db-maria @@ -21,6 +21,10 @@ synopsis() { printf "\t restore \n" printf "\t ---------------------------\n" printf "\t rename \n" + + if [[ "$TARGET" != 'prod' ]]; then + printf "\t drop # unless PROD!\n" + fi } list() { @@ -163,10 +167,17 @@ rename() { console "drop database \\\`$DB_NAME\\\`" } +drop() { + console "drop user \\\`$DB_NAME\\\`" + console "drop database \\\`$DB_NAME\\\`" + echo "$DB_NAME dropped!" +} + # MAIN set -Eeuo pipefail # shellcheck source=/dev/null . "$MIAOU_BASEDIR/lib/functions.sh" +TARGET=$(grep -Es "^target:" /etc/miaou/defaults.yaml | cut -d ' ' -f2) [[ $# -lt 1 ]] && synopsis && exit 1 ACTION=$1 @@ -214,6 +225,12 @@ rename) NEW_NAME=$3 rename ;; +drop) + [[ $# -lt 2 ]] && synopsis && exit 1 + [[ "$TARGET" = 'prod' ]] && synopsis && exit 2 + DB_NAME=$2 + drop + ;; *) synopsis exit 1 diff --git a/scripts/db-psql b/scripts/db-psql index 3809009..43ca6c5 100755 --- a/scripts/db-psql +++ b/scripts/db-psql @@ -20,6 +20,9 @@ synopsis() { printf "\t restore [--yes]\n" printf "\t ---------------------------\n" printf "\t rename \n" + if [[ "$TARGET" != 'prod' ]]; then + printf "\t drop # unless PROD!\n" + fi } list() { @@ -134,11 +137,17 @@ rename() { 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_NEW_NAME\\\" PASSWORD '$DB_NEW_NAME' \"" +} +drop() { + console "dropdb $DB_NAME" + console "dropuser $DB_NAME" + echo "$DB_NAME dropped!" } # MAIN . "$MIAOU_BASEDIR/lib/init.sh" +TARGET=$(grep -Es "^target:" /etc/miaou/defaults.yaml | cut -d ' ' -f2) [[ $# -lt 1 ]] && synopsis && exit 1 ACTION=$1 @@ -193,6 +202,12 @@ rename) DB_NEW_NAME=$3 rename ;; +drop) + [[ $# -lt 2 ]] && synopsis && exit 1 + [[ "$TARGET" = 'prod' ]] && synopsis && exit 2 + DB_NAME=$2 + drop + ;; *) synopsis exit 1