From cf140bc75fa6852e92c31035696cde9372fd724c Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Sat, 30 Sep 2023 05:46:57 +0200 Subject: [PATCH] IDEMPIERE-5868 RUN_MonitoredSyncDB ordered by timestamp can have issues (#2030) --- .../utils.unix/oracle/MonitoredSyncDB.sh | 22 ++++++++++------- .../utils.unix/oracle/SyncDB.sh | 0 .../utils.unix/postgresql/MonitoredSyncDB.sh | 24 ++++++++++++------- .../utils.unix/postgresql/SyncDB.sh | 2 +- 4 files changed, 30 insertions(+), 18 deletions(-) mode change 100644 => 100755 org.adempiere.server-feature/utils.unix/oracle/SyncDB.sh mode change 100644 => 100755 org.adempiere.server-feature/utils.unix/postgresql/SyncDB.sh diff --git a/org.adempiere.server-feature/utils.unix/oracle/MonitoredSyncDB.sh b/org.adempiere.server-feature/utils.unix/oracle/MonitoredSyncDB.sh index 1d77d52b07..9e5f51a5fd 100755 --- a/org.adempiere.server-feature/utils.unix/oracle/MonitoredSyncDB.sh +++ b/org.adempiere.server-feature/utils.unix/oracle/MonitoredSyncDB.sh @@ -17,10 +17,10 @@ # It is expected that the script 001.fix always end registering calling register_migration_script # and also cleaning the Error status from the script that is fixing via update, for example: # script 201811121420_IDEMPIERE-2648.001.fix is expected to end with these two lines: -# UPDATE AD_MigrationScript SET Status='IP' WHERE Name='201811121420_IDEMPIERE-2648.sql'); +# UPDATE AD_MigrationScript SET Status='IP' WHERE Name='201811121420_IDEMPIERE-2648.sql'; # SELECT register_migration_script('201811121420_IDEMPIERE-2648.001.fix') FROM dual; # and similar the script 201811121420_IDEMPIERE-2648.002.fix is expected to end with these two lines: -# UPDATE AD_MigrationScript SET Status='IP' WHERE Name='201811121420_IDEMPIERE-2648.001.fix'); +# UPDATE AD_MigrationScript SET Status='IP' WHERE Name='201811121420_IDEMPIERE-2648.001.fix'; # SELECT register_migration_script('201811121420_IDEMPIERE-2648.002.fix') FROM dual; # and so on # 4. If there is an email registered in AD_System.SupportEMail and there is an accessible sendmail program then @@ -62,15 +62,15 @@ if [ "x$4" = "x" ] then DIR_SCRIPTS=$IDEMPIERE_HOME/migration else - if [ "${4#/}" = "${4}" ] + if [ "${4:0:1}" = "/" ] then - DIR_SCRIPTS="$IDEMPIERE_HOME/$4" - else DIR_SCRIPTS="$4" + else + DIR_SCRIPTS="$IDEMPIERE_HOME/$4" fi fi -cd "$DIR_SCRIPTS" || exit 1 +cd "$DIR_SCRIPTS" || (echo "ERROR: Cannot change to folder $DIR_SCRIPTS"; exit 1) mkdir $TMPFOLDER/SyncDB_out_$$ @@ -233,7 +233,13 @@ then while read -r FILE do SCRIPT=$(find . -name "$FILE" | grep "/$ADEMPIERE_DB_PATH/") - OUTFILE=$TMPFOLDER/SyncDB_out_$$/$(basename "$FILE" .sql).out + echo "$SCRIPT" >> $TMPFOLDER/lisPENDINGFOL_$$.txt + done < $TMPFOLDER/lisPENDING_$$.txt + sort -o $TMPFOLDER/lisPENDINGFOL_$$.txt $TMPFOLDER/lisPENDINGFOL_$$.txt + while read -r SCRIPT + do + OUTFILE=$TMPFOLDER/SyncDB_out_$$/$(basename "$SCRIPT" .sql).out + FILE=$(basename "$SCRIPT") if ! apply_script "$SCRIPT" "$OUTFILE" "$FILE" then TMPMSGERROR="\n**** ERROR ON FILE $OUTFILE - Please verify ****" @@ -250,7 +256,7 @@ then # Stop processing, problem must be fixed break fi - done < $TMPFOLDER/lisPENDING_$$.txt + done < $TMPFOLDER/lisPENDINGFOL_$$.txt else if [ -s $TMPFOLDER/lisFS_$$.txt ] then diff --git a/org.adempiere.server-feature/utils.unix/oracle/SyncDB.sh b/org.adempiere.server-feature/utils.unix/oracle/SyncDB.sh old mode 100644 new mode 100755 diff --git a/org.adempiere.server-feature/utils.unix/postgresql/MonitoredSyncDB.sh b/org.adempiere.server-feature/utils.unix/postgresql/MonitoredSyncDB.sh index e535dc3f6e..b2c9aa5a02 100755 --- a/org.adempiere.server-feature/utils.unix/postgresql/MonitoredSyncDB.sh +++ b/org.adempiere.server-feature/utils.unix/postgresql/MonitoredSyncDB.sh @@ -17,10 +17,10 @@ # It is expected that the script 001.fix always end registering calling register_migration_script # and also cleaning the Error status from the script that is fixing via update, for example: # script 201811121420_IDEMPIERE-2648.001.fix is expected to end with these two lines: -# UPDATE AD_MigrationScript SET Status='IP' WHERE Name='201811121420_IDEMPIERE-2648.sql'); +# UPDATE AD_MigrationScript SET Status='IP' WHERE Name='201811121420_IDEMPIERE-2648.sql'; # SELECT register_migration_script('201811121420_IDEMPIERE-2648.001.fix') FROM dual; # and similar the script 201811121420_IDEMPIERE-2648.002.fix is expected to end with these two lines: -# UPDATE AD_MigrationScript SET Status='IP' WHERE Name='201811121420_IDEMPIERE-2648.001.fix'); +# UPDATE AD_MigrationScript SET Status='IP' WHERE Name='201811121420_IDEMPIERE-2648.001.fix'; # SELECT register_migration_script('201811121420_IDEMPIERE-2648.002.fix') FROM dual; # and so on # 4. If there is an email registered in AD_System.SupportEMail and there is an accessible sendmail program then @@ -74,15 +74,15 @@ if [ "x$4" = "x" ] then DIR_SCRIPTS=$IDEMPIERE_HOME/migration else - if [ "${4#/}" = "${4}" ] + if [ "${4:0:1}" = "/" ] then - DIR_SCRIPTS="$IDEMPIERE_HOME/$4" - else DIR_SCRIPTS="$4" + else + DIR_SCRIPTS="$IDEMPIERE_HOME/$4" fi fi -cd "$DIR_SCRIPTS" || exit 1 +cd "$DIR_SCRIPTS" || (echo "ERROR: Cannot change to folder $DIR_SCRIPTS"; exit 1) mkdir $TMPFOLDER/SyncDB_out_$$ @@ -218,7 +218,7 @@ do fi done < $TMPFOLDER/lisERR_$$.txt -# Create list of files already applied - registered in ad_migrationscript table +# Create list of files already applied - registered in AD_MigrationScript table echo "select name from ad_migrationscript" | $SILENTCMD | sed -e 's:^ ::' | grep -v '^$' | sort > $TMPFOLDER/lisDB_$$.txt # Create list of files in the migration folder @@ -232,7 +232,13 @@ then while read -r FILE do SCRIPT=$(find . -name "$FILE" | grep "/$ADEMPIERE_DB_PATH/") - OUTFILE=$TMPFOLDER/SyncDB_out_$$/$(basename "$FILE" .sql).out + echo "$SCRIPT" >> $TMPFOLDER/lisPENDINGFOL_$$.txt + done < $TMPFOLDER/lisPENDING_$$.txt + sort -o $TMPFOLDER/lisPENDINGFOL_$$.txt $TMPFOLDER/lisPENDINGFOL_$$.txt + while read -r SCRIPT + do + OUTFILE=$TMPFOLDER/SyncDB_out_$$/$(basename "$SCRIPT" .sql).out + FILE=$(basename "$SCRIPT") if ! apply_script "$SCRIPT" "$OUTFILE" "$FILE" then TMPMSGERROR="\n**** ERROR ON FILE $OUTFILE - Please verify ****" @@ -249,7 +255,7 @@ then # Stop processing, problem must be fixed break fi - done < $TMPFOLDER/lisPENDING_$$.txt + done < $TMPFOLDER/lisPENDINGFOL_$$.txt else if [ -s $TMPFOLDER/lisFS_$$.txt ] then diff --git a/org.adempiere.server-feature/utils.unix/postgresql/SyncDB.sh b/org.adempiere.server-feature/utils.unix/postgresql/SyncDB.sh old mode 100644 new mode 100755 index d44bb27108..c2492f5fe6 --- a/org.adempiere.server-feature/utils.unix/postgresql/SyncDB.sh +++ b/org.adempiere.server-feature/utils.unix/postgresql/SyncDB.sh @@ -29,7 +29,7 @@ export PGPASSWORD TMPFOLDER=/tmp ADEMPIERE_DB_USER=$1 ADEMPIERE_DB_PATH=$3 -CMD="psql -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -d $ADEMPIERE_DB_NAME -U $ADEMPIERE_DB_USER -b" +CMD="psql -b -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -d $ADEMPIERE_DB_NAME -U $ADEMPIERE_DB_USER -b" SILENTCMD="$CMD -q -t" ERROR_STRINGS="^(ERROR:|FEHLER:|FATAL:|ERRO:)" DIR_POST=$IDEMPIERE_HOME/migration