From 5b5017b4c3e5893b0ea109cedd2be61142fea8ac Mon Sep 17 00:00:00 2001 From: rjshrjndrn Date: Mon, 27 Feb 2023 14:22:33 +0100 Subject: [PATCH] fix(script): check migration versions Signed-off-by: rjshrjndrn --- scripts/helmcharts/openreplay/files/dbops.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scripts/helmcharts/openreplay/files/dbops.sh b/scripts/helmcharts/openreplay/files/dbops.sh index 21ace9d2c..6402a3c88 100644 --- a/scripts/helmcharts/openreplay/files/dbops.sh +++ b/scripts/helmcharts/openreplay/files/dbops.sh @@ -33,7 +33,13 @@ function migration() { # Checking migration versions cd /opt/openreplay/openreplay/scripts/schema - migration_versions=(`ls -l db/init_dbs/$db | grep -E ^d | awk -v number=${PREVIOUS_APP_VERSION} '$NF > number {print $NF}' | grep -v create`) + + # We need to remove version dots + function normalise_version { + echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }' + } + all_versions=(`ls -l db/init_dbs/$db | grep -E ^d | grep -v create | awk '{print $NF}'`) + migration_versions=(`for ver in ${all_versions[*]}; do if [[ $(normalise_version $ver) > $(normalise_version "${PREVIOUS_APP_VERSION}") ]]; then echo $ver; fi; done`) echo "Migration version: ${migration_versions[*]}" # Can't pass the space seperated array to ansible for migration. So joining them with , joined_migration_versions=$(IFS=, ; echo "${migration_versions[*]}")