db_pending/import now use transaction to avoid db data inconsistency
This commit is contained in:
@@ -12,37 +12,46 @@ function import() {
|
|||||||
folder="db_"$1
|
folder="db_"$1
|
||||||
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 $updPath/ -1 | tail -n 1`
|
latestUpd=`ls $updPath/ -1 | 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;
|
exit;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
dateToday=`date +%Y_%m_%d`
|
dateToday=`date +%Y_%m_%d`
|
||||||
counter=0
|
counter=0
|
||||||
|
|
||||||
dateLast=$latestUpd
|
dateLast=$latestUpd
|
||||||
tmp=${dateLast#*_*_*_}
|
tmp=${dateLast#*_*_*_}
|
||||||
oldCnt=${tmp%.sql}
|
oldCnt=${tmp%.sql}
|
||||||
oldDate=${dateLast%_$tmp}
|
oldDate=${dateLast%_$tmp}
|
||||||
|
|
||||||
if [ "$oldDate" = "$dateToday" ]; then
|
if [ "$oldDate" = "$dateToday" ]; then
|
||||||
((counter=$oldCnt+1))
|
((counter=$oldCnt+1))
|
||||||
fi;
|
fi;
|
||||||
|
|
||||||
for entry in "$pendingPath"/*.sql
|
for entry in "$pendingPath"/*.sql
|
||||||
do
|
do
|
||||||
if [[ -e $entry ]]; then
|
if [[ -e $entry ]]; then
|
||||||
|
startTransaction="START TRANSACTION;";
|
||||||
updHeader="ALTER TABLE db_version CHANGE COLUMN "$latestUpd" "$dateToday"_"$counter" bit;";
|
updHeader="ALTER TABLE db_version CHANGE COLUMN "$latestUpd" "$dateToday"_"$counter" bit;";
|
||||||
|
endTransaction="COMMIT;";
|
||||||
|
|
||||||
cnt=$(printf -v counter "%02d" $counter ; echo $counter)
|
cnt=$(printf -v counter "%02d" $counter ; echo $counter)
|
||||||
newFile="$updPath/"$dateToday"_"$cnt".sql"
|
newFile="$updPath/"$dateToday"_"$cnt".sql"
|
||||||
echo "$updHeader" > "$newFile"
|
|
||||||
|
echo "$startTransaction" > "$newFile"
|
||||||
|
echo "$updHeader" >> "$newFile"
|
||||||
echo "--" >> "$newFile"
|
echo "--" >> "$newFile"
|
||||||
echo "--" >> "$newFile"
|
echo "--" >> "$newFile"
|
||||||
|
|
||||||
cat $entry >> "$newFile"
|
cat $entry >> "$newFile"
|
||||||
|
echo "$endTransaction" >> "$newFile"
|
||||||
|
|
||||||
rm $entry
|
rm $entry
|
||||||
|
|
||||||
((counter+=1))
|
((counter+=1))
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user