aboutsummaryrefslogtreecommitdiffstats
path: root/policy-db-migrator
diff options
context:
space:
mode:
authorktimoney <kevin.timoney@est.tech>2021-09-20 17:20:51 +0100
committerktimoney <kevin.timoney@est.tech>2021-09-21 16:53:37 +0100
commit6d1dfc12e5648cdf361b678575b946a5ff2f8ec7 (patch)
treea0640cd90f4c55afe943bffe17585d1021a8685c /policy-db-migrator
parent7ba2e041f859829fac74071312503f8b5891ad38 (diff)
Update db-migrator version checks
DB-Migrator job completes even during failed upgrade Issue-ID: POLICY-3660 Change-Id: I7295c740853e4dd533e989faa3dddebab4d4ccab Signed-off-by: ktimoney <kevin.timoney@est.tech>
Diffstat (limited to 'policy-db-migrator')
-rwxr-xr-xpolicy-db-migrator/src/main/docker/db-migrator77
1 files changed, 35 insertions, 42 deletions
diff --git a/policy-db-migrator/src/main/docker/db-migrator b/policy-db-migrator/src/main/docker/db-migrator
index dd29dfaa..785dd834 100755
--- a/policy-db-migrator/src/main/docker/db-migrator
+++ b/policy-db-migrator/src/main/docker/db-migrator
@@ -422,28 +422,10 @@ function upgrade
set -x
fi
- local sqlName sqlFile schemaVersion upgradeSqls rc tagDate tag retry compare
+ local sqlName sqlFile schemaVersion upgradeSqls rc tagDate tag
tagDate=$(date +%d%m%y%H%M%S)
- retry=0
echo "upgrade: ${CURRENT_RELEASE} -> ${TARGET_UPGRADE_RELEASE}"
- last_operation_status
- rc=$?
- if [ $rc -eq 0 ]; then
- echo "Partial $LAST_OPERATION detected"
- retry=1
- if [ "${LAST_OPERATION}" == 'upgrade' ]; then
- CURRENT_RELEASE="${LAST_FROM_VERSION}"
- # less than
- compare="lt"
- echo "Upgrade will attempt to resume at $LAST_SCRIPT"
- else
- CURRENT_RELEASE="${LAST_TO_VERSION}"
- # less than or equal
- compare="le"
- echo "Upgrade will attempt to resume after $LAST_SCRIPT"
- fi
- fi
if [ ${CURRENT_RELEASE} \< ${TARGET_UPGRADE_RELEASE} ]; then
upgradeSqls=$(ls -v "${UPGRADE_DIR}"/*/upgrade/*.sql 2> /dev/null)
@@ -454,9 +436,9 @@ function upgrade
if [ "${schemaVersion}" -gt "${CURRENT_RELEASE}" ] && \
[ "${schemaVersion}" -le "${TARGET_UPGRADE_RELEASE}" ]; then
tag=${tagDate}"${schemaVersion}u"
- if [ $retry -eq 1 ] && \
+ if [ $RETRY -eq 1 ] && \
# Compare the numeric portion of the filename because shell doesn't support string comparison
- [ $(echo ${sqlName}| awk -F- '{print $1}') -${compare} $(echo ${LAST_SCRIPT}| awk -F- '{print $1}') ]; then
+ [ $(echo ${sqlName}| awk -F- '{print $1}') -${COMPARE} $(echo ${LAST_SCRIPT}| awk -F- '{print $1}') ]; then
rc=1
else
rc=0
@@ -490,28 +472,10 @@ function downgrade
set -x
fi
- local sqlName sqlFile schemaVersion downgradeSqls rc tagDate tag retry compare
+ local sqlName sqlFile schemaVersion downgradeSqls rc tagDate tag
tagDate=$(date +%d%m%y%H%M%S)
- retry=0
echo "downgrade: ${CURRENT_RELEASE} -> ${TARGET_DOWNGRADE_RELEASE}"
- last_operation_status
- rc=$?
- if [ $rc -eq 0 ]; then
- echo "Partial $LAST_OPERATION detected"
- retry=1
- if [ "${LAST_OPERATION}" == 'downgrade' ]; then
- CURRENT_RELEASE="${LAST_FROM_VERSION}"
- # greater than
- compare="gt"
- echo "Downgrade will attempt to resume at $LAST_SCRIPT"
- else
- CURRENT_RELEASE="${LAST_TO_VERSION}"
- # greater than or equal to
- compare="ge"
- echo "Downgrade will attempt to resume before $LAST_SCRIPT"
- fi
- fi
if [ ${CURRENT_RELEASE} \> ${TARGET_DOWNGRADE_RELEASE} ]; then
downgradeSqls=$(ls -v -r "${DOWNGRADE_DIR}"/*/downgrade/*.sql 2> /dev/null)
@@ -521,9 +485,9 @@ function downgrade
if [ "${schemaVersion}" -le "${CURRENT_RELEASE}" ] && \
[ "${schemaVersion}" -gt "${TARGET_DOWNGRADE_RELEASE}" ]; then
tag=${tagDate}"${schemaVersion}d"
- if [ $retry -eq 1 ] && \
+ if [ $RETRY -eq 1 ] && \
# Compare the numeric portion of the filename because shell doesn't support string comparison
- [ $(echo ${sqlName}| awk -F- '{print $1}') -${compare} $(echo ${LAST_SCRIPT}| awk -F- '{print $1}') ]; then
+ [ $(echo ${sqlName}| awk -F- '{print $1}') -${COMPARE} $(echo ${LAST_SCRIPT}| awk -F- '{print $1}') ]; then
rc=1
else
rc=0
@@ -745,6 +709,35 @@ for dbPath in ${SCHEMA_S}; do
# Check if the schema has already been installed
current_schema
+ RETRY=0
+ COMPARE=""
+ last_operation_status
+ last_status=$?
+ if [ $last_status -eq 0 ]; then
+ echo "Partial $LAST_OPERATION detected"
+ RETRY=1
+ if [ "${OPERATION}" == 'downgrade' ] && [ "${LAST_OPERATION}" == 'downgrade' ]; then
+ CURRENT_RELEASE="${LAST_FROM_VERSION}"
+ # greater than
+ COMPARE="gt"
+ echo "Downgrade will attempt to resume at $LAST_SCRIPT"
+ elif [ "${OPERATION}" == 'downgrade' ] && [ "${LAST_OPERATION}" == 'upgrade' ]; then
+ CURRENT_RELEASE="${LAST_TO_VERSION}"
+ # greater than or equal to
+ COMPARE="ge"
+ echo "Downgrade will attempt to resume before $LAST_SCRIPT"
+ elif [ "${OPERATION}" == 'upgrade' ] && [ "${LAST_OPERATION}" == 'upgrade' ]; then
+ CURRENT_RELEASE="${LAST_FROM_VERSION}"
+ # less than
+ COMPARE="lt"
+ echo "Upgrade will attempt to resume at $LAST_SCRIPT"
+ else
+ CURRENT_RELEASE="${LAST_TO_VERSION}"
+ # less than or equal
+ COMPARE="le"
+ echo "Upgrade will attempt to resume after $LAST_SCRIPT"
+ fi
+ fi
if [ -n "${INPUT_FROM_RELEASE}" ]; then
if [ "${CURRENT_RELEASE}" \> "${INPUT_FROM_RELEASE}" ] || [ "${CURRENT_RELEASE}" \< "${INPUT_FROM_RELEASE}" ]; then