From a12ef2c290bd2ec715346188e631b7922b7af5d1 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Wed, 3 Apr 2019 12:09:45 +0200 Subject: [PATCH] DB versioning fixes --- db/import-changes.sh | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/db/import-changes.sh b/db/import-changes.sh index 9ba774b98..aecb2014e 100755 --- a/db/import-changes.sh +++ b/db/import-changes.sh @@ -43,7 +43,7 @@ if [ "$ENV" == "production" ]; then if [ "$ANSWER" != "yes" ]; then echo "[INFO] Aborting changes." - exit; + exit fi fi fi @@ -57,7 +57,7 @@ else fi if [ ! -f "$INI_FILE" ]; then - echo "[ERROR] Config file doesn't exists: $INI_FILE" + echo "[ERROR] Config file doesn't exists: $INI_FILE" exit 2 fi @@ -83,18 +83,25 @@ echo "[INFO] Applying changes." for VERSION_DIR in "$DIR/changes/"*; do DIR_VERSION=$(basename $VERSION_DIR) - if [ "$DB_VERSION" -lt "$DIR_VERSION" ]; then - echo "[INFO] Applying version: $DIR_VERSION" - - for FILE in "$VERSION_DIR/"*; do - echo "[INFO] -> $(basename "$FILE")" - mysql --defaults-file="$INI_FILE" --comments < $FILE - N_CHANGES=$((N_CHANGES + 1)) - done - - UPDATE_VERSION="UPDATE util.config SET dbVersion='$DIR_VERSION'" - echo "$UPDATE_VERSION" | mysql --defaults-file="$INI_FILE" + if [[ ! "$DIR_VERSION" =~ ^[0-9]{5}$ ]]; then + echo "[INFO] Ignoring wrong version number: $DIR_VERSION" + continue fi + if [ "$DB_VERSION" -ge "$DIR_VERSION" ]; then + echo "[INFO] Ignoring already applied version: $DIR_VERSION" + continue + fi + + echo "[INFO] Applying version: $DIR_VERSION" + + for FILE in "$VERSION_DIR/"*; do + echo "[INFO] -> $(basename "$FILE")" + mysql --defaults-file="$INI_FILE" --comments < $FILE + N_CHANGES=$((N_CHANGES + 1)) + done + + UPDATE_VERSION="UPDATE util.config SET dbVersion='$DIR_VERSION'" + echo "$UPDATE_VERSION" | mysql --defaults-file="$INI_FILE" done if [ "$N_CHANGES" -eq "0" ]; then