From 0b34a24cf91040646741428ce86af6700d721df0 Mon Sep 17 00:00:00 2001 From: Yehonal Date: Fri, 26 Aug 2016 16:24:50 +0200 Subject: [PATCH] db_pending/import now use transaction to avoid db data inconsistency --- bin/db_pendings/import.sh | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/bin/db_pendings/import.sh b/bin/db_pendings/import.sh index 26f1f2168..e0497bf54 100755 --- a/bin/db_pendings/import.sh +++ b/bin/db_pendings/import.sh @@ -12,37 +12,46 @@ function import() { folder="db_"$1 pendingPath="$AC_PATH_ROOT/data/sql/updates/pending_$folder" updPath="$UPDATES_PATH/$folder" - + latestUpd=`ls $updPath/ -1 | tail -n 1` - + if [ -z $latestUpd ]; then echo "FIRST UPDATE FILE MISSING!! DID YOU ARCHIVED IT?"; exit; fi - + dateToday=`date +%Y_%m_%d` counter=0 - + dateLast=$latestUpd tmp=${dateLast#*_*_*_} oldCnt=${tmp%.sql} oldDate=${dateLast%_$tmp} - + if [ "$oldDate" = "$dateToday" ]; then ((counter=$oldCnt+1)) fi; - + for entry in "$pendingPath"/*.sql do if [[ -e $entry ]]; then + startTransaction="START TRANSACTION;"; updHeader="ALTER TABLE db_version CHANGE COLUMN "$latestUpd" "$dateToday"_"$counter" bit;"; + endTransaction="COMMIT;"; + cnt=$(printf -v counter "%02d" $counter ; echo $counter) newFile="$updPath/"$dateToday"_"$cnt".sql" - echo "$updHeader" > "$newFile" + + echo "$startTransaction" > "$newFile" + echo "$updHeader" >> "$newFile" echo "--" >> "$newFile" echo "--" >> "$newFile" + cat $entry >> "$newFile" + echo "$endTransaction" >> "$newFile" + rm $entry + ((counter+=1)) fi done