aboutsummaryrefslogtreecommitdiffstats
path: root/policy-db-migrator/src/main/docker/db-migrator
diff options
context:
space:
mode:
Diffstat (limited to 'policy-db-migrator/src/main/docker/db-migrator')
-rwxr-xr-xpolicy-db-migrator/src/main/docker/db-migrator82
1 files changed, 14 insertions, 68 deletions
diff --git a/policy-db-migrator/src/main/docker/db-migrator b/policy-db-migrator/src/main/docker/db-migrator
index d66797c1..1d3fe4a3 100755
--- a/policy-db-migrator/src/main/docker/db-migrator
+++ b/policy-db-migrator/src/main/docker/db-migrator
@@ -323,52 +323,6 @@ function previous_release
return 0
}
-#####################################################
-# object_exists
-#####################################################
-
-function object_exists
-{
- if [ "${DEBUG}" = "y" ]; then
- echo "-- object_exists --"
- set -x
- fi
-
- local sqlFile="${1}"
- local query rc objectType objectName
-
- objectName=$(basename ${sqlFile} .sql | cut -f2 -d-)
-
- rc=$(cat ${sqlFile} | awk '/ALTER/ && /CONSTRAINT/' | wc -l)
- if [ $rc -gt 0 ]; then
- objectType="constraint"
- else
- rc=$(cat ${sqlFile} | awk '/INDEX/' | wc -l)
- if [ $rc -gt 0 ]; then
- objectType="index"
- else
- objectType="table"
- fi
- fi
-
- if [ "${objectType}" == "constraint" ]; then
- query="SELECT IF (constraint_count>0, TRUE, FALSE) as constraint_exists FROM "
- query=${query}"(SELECT count(1) as constraint_count from INFORMATION_SCHEMA.TABLE_CONSTRAINTS "
- query=${query}"WHERE lower(constraint_name)=lower('${objectName}') AND table_schema='${SCHEMA}') t"
- elif [ "${objectType}" == "index" ]; then
- query="SELECT IF (index_count>0, TRUE, FALSE) as index_exists FROM "
- query=${query}"(SELECT count(1) as index_count FROM INFORMATION_SCHEMA.STATISTICS "
- query=${query}"WHERE lower(index_name)=lower('${objectName}') AND index_schema='${SCHEMA}') t"
- else
- query="SELECT IF (table_count>0, TRUE, FALSE) as table_exists FROM "
- query=${query}"(SELECT count(1) as table_count FROM INFORMATION_SCHEMA.TABLES "
- query=${query}"WHERE lower(table_name)=lower('${objectName}') AND table_schema='${SCHEMA}') t"
- fi
-
- rc=$(${MYSQL} --skip-column-names --silent --execute "${query}")
-
- return $rc;
-}
#####################################################
# last_operation_status
@@ -508,17 +462,13 @@ function upgrade
rc=0
fi
if [ ${rc} -eq 0 ]; then
- object_exists ${sqlFile}
- rc=$?
- if [ ${rc} -eq 0 ]; then
- run_script "upgrade" "${sqlName}" "${sqlFile}" "${PREVIOUS_RELEASE}" "${schemaVersion}" "${tag}"
- rc=$?
- if [ ${rc} -ne 0 ]; then
- echo "${SCHEMA}: upgrade aborted at ${schemaVersion} by script ${sqlName}"
- set_current_release "${schemaVersion}"
- return ${rc}
- fi
- fi
+ run_script "upgrade" "${sqlName}" "${sqlFile}" "${PREVIOUS_RELEASE}" "${schemaVersion}" "${tag}"
+ rc=$?
+ if [ ${rc} -ne 0 ]; then
+ echo "${SCHEMA}: upgrade aborted at ${schemaVersion} by script ${sqlName}"
+ set_current_release "${schemaVersion}"
+ return ${rc}
+ fi
fi
fi
done
@@ -579,17 +529,13 @@ function downgrade
rc=0
fi
if [ ${rc} -eq 0 ]; then
- object_exists ${sqlFile}
- rc=$?
- if [ ${rc} -eq 1 ]; then
- run_script "downgrade" "${sqlName}" "${sqlFile}" "${schemaVersion}" "${PREVIOUS_RELEASE}" ${tag}
- rc=$?
- if [ ${rc} -ne 0 ]; then
- echo "${SCHEMA}: downgrade aborted at ${schemaVersion} by script ${sqlName}"
- set_current_release "${schemaVersion}"
- return ${rc}
- fi
- fi
+ run_script "downgrade" "${sqlName}" "${sqlFile}" "${schemaVersion}" "${PREVIOUS_RELEASE}" ${tag}
+ rc=$?
+ if [ ${rc} -ne 0 ]; then
+ echo "${SCHEMA}: downgrade aborted at ${schemaVersion} by script ${sqlName}"
+ set_current_release "${schemaVersion}"
+ return ${rc}
+ fi
fi
fi
done