fix(bash): restored import sql script

Codacity suggestions are causing bugs here.
It would be better to convert it in Typescript in future.
This commit is contained in:
Yehonal
2021-06-16 17:40:23 +02:00
parent 1e2b880301
commit d4d2a17a96

View File

@@ -14,14 +14,14 @@ function import() {
pendingPath="$AC_PATH_ROOT/data/sql/updates/pending_$folder" pendingPath="$AC_PATH_ROOT/data/sql/updates/pending_$folder"
updPath="$UPDATES_PATH/$folder" updPath="$UPDATES_PATH/$folder"
latestUpd=$(ls -1 $updPath/ | tail -n 1) latestUpd=`ls -1 $updPath/ | tail -n 1`
if [ -z $latestUpd ]; then if [ -z $latestUpd ]; then
echo "FIRST UPDATE FILE MISSING!! DID YOU ARCHIVED IT?"; echo "FIRST UPDATE FILE MISSING!! DID YOU ARCHIVED IT?";
exit 1; exit;
fi fi
dateToday=$(date +%Y_%m_%d) dateToday=`date +%Y_%m_%d`
counter=0 counter=0
dateLast=$latestUpd dateLast=$latestUpd
@@ -43,10 +43,10 @@ function import() {
newVer=$dateToday"_"$cnt newVer=$dateToday"_"$cnt
startTransaction="START TRANSACTION;"; startTransaction="START TRANSACTION;";
updHeader="ALTER TABLE version_db_$db CHANGE COLUMN $oldVer $newVer bit;"; updHeader="ALTER TABLE version_db_"$db" CHANGE COLUMN "$oldVer" "$newVer" bit;";
endTransaction="COMMIT;"; endTransaction="COMMIT;";
newFile="$updPath/$dateToday_$cnt.sql" newFile="$updPath/"$dateToday"_"$cnt".sql"
oldFile=$(basename "$entry") oldFile=$(basename "$entry")
prefix=${oldFile%_*.sql} prefix=${oldFile%_*.sql}
@@ -67,7 +67,7 @@ function import() {
echo "proc:BEGIN DECLARE OK VARCHAR(100) DEFAULT 'FALSE';" >> "$newFile"; echo "proc:BEGIN DECLARE OK VARCHAR(100) DEFAULT 'FALSE';" >> "$newFile";
echo "SELECT COUNT(*) INTO @COLEXISTS" >> "$newFile"; echo "SELECT COUNT(*) INTO @COLEXISTS" >> "$newFile";
echo "FROM information_schema.COLUMNS" >> "$newFile"; echo "FROM information_schema.COLUMNS" >> "$newFile";
echo "WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'version_db_$db' AND COLUMN_NAME = '$oldVer';" >> "$newFile"; echo "WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'version_db_"$db"' AND COLUMN_NAME = '"$oldVer"';" >> "$newFile";
echo "IF @COLEXISTS = 0 THEN LEAVE proc; END IF;" >> "$newFile"; echo "IF @COLEXISTS = 0 THEN LEAVE proc; END IF;" >> "$newFile";
fi fi
@@ -75,7 +75,7 @@ function import() {
echo "$updHeader" >> "$newFile"; echo "$updHeader" >> "$newFile";
if [[ $isRev -eq 1 ]]; then if [[ $isRev -eq 1 ]]; then
echo "SELECT sql_rev INTO OK FROM version_db_$db WHERE sql_rev = '$rev'; IF OK <> 'FALSE' THEN LEAVE proc; END IF;" >> "$newFile"; echo "SELECT sql_rev INTO OK FROM version_db_"$db" WHERE sql_rev = '$rev'; IF OK <> 'FALSE' THEN LEAVE proc; END IF;" >> "$newFile";
fi; fi;
echo "--" >> "$newFile"; echo "--" >> "$newFile";
@@ -89,7 +89,7 @@ function import() {
echo "--" >> "$newFile"; echo "--" >> "$newFile";
echo "-- END UPDATING QUERIES" >> "$newFile"; echo "-- END UPDATING QUERIES" >> "$newFile";
echo "--" >> "$newFile"; echo "--" >> "$newFile";
echo "UPDATE version_db_$db SET date = '$newVer' WHERE sql_rev = '$rev';" >> "$newFile"; echo "UPDATE version_db_"$db" SET date = '"$newVer"' WHERE sql_rev = '"$rev"';" >> "$newFile";
echo "$endTransaction" >> "$newFile"; echo "$endTransaction" >> "$newFile";