From 0b560e17496b37a3cfc18a87da898f6e624a9510 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 12 Mar 2019 16:38:43 +0100 Subject: [PATCH] DB import script fixes --- db/import-changes.sh | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/db/import-changes.sh b/db/import-changes.sh index d9042cf3c..498390b51 100755 --- a/db/import-changes.sh +++ b/db/import-changes.sh @@ -1,5 +1,26 @@ #!/bin/bash +FORCE=FALSE + +usage() { + echo "Usage: $0 [-f] [environment]" + exit 1 +} + +while getopts ":f" option +do + case $option in + f) + FORCE=TRUE + ;; + \?|:) + usage + ;; + esac +done + +shift $(($OPTIND - 1)) + ENV=$1 if [ "$ENV" == "production" ]; then @@ -14,11 +35,13 @@ if [ "$ENV" == "production" ]; then echo "|_| |_|_\ \___/|___/ \___/ \___| |_| |___| \___/|_|\_|" echo "" - read -p "Are you sure? (Default: no) [yes|no]: " ANSWER + if [ "$FORCE" != "TRUE" ]; then + read -p "Are you sure? (Default: no) [yes|no]: " ANSWER - if [ "$ANSWER" != "yes" ]; then - echo "Aborting" - exit; + if [ "$ANSWER" != "yes" ]; then + echo "Aborting" + exit; + fi fi fi if [ -z "$ENV" ]; then @@ -28,15 +51,16 @@ fi INI_FILE="config.$ENV.ini" if [ ! -f "$INI_FILE" ]; then - echo "File $INI_FILE doesn't exists" - exit 1 + echo "Config file doesn't exists: $INI_FILE" + exit 2 fi echo "[INFO] Config file: $INI_FILE" -echo "[INFO] Importing changes." +echo "[INFO] Applying changes" # Import changes for file in install/changes/*.sql; do - echo "[INFO] -> Applying $file" + echo "[INFO] -> $file" mysql --defaults-file="$INI_FILE" < $file done +