aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-07-29 13:42:40 +0000
committerGerrit Code Review <gerrit@onap.org>2021-07-29 13:42:40 +0000
commitee879f853121d92816945f0f6d0486af67a84439 (patch)
tree41f1cfa01f0822840c6ec6f5e4be34deeb18818f
parent89176a2eaf465b2a383a3dd6bea93f936698b31b (diff)
parentf846018c684132e2a09de93a337fc7d9a31a3280 (diff)
Merge "Update db-migrator to include ability to deal with partial installs"
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0830-FK_ToscaNodeTemplate_capabilitiesName.sql4
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0840-FK_ToscaNodeTemplate_requirementsName.sql2
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0850-FK_ToscaNodeType_requirementsName.sql2
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0860-FK_ToscaServiceTemplate_capabilityTypesName.sql2
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0870-FK_ToscaServiceTemplate_dataTypesName.sql2
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0880-FK_ToscaServiceTemplate_nodeTypesName.sql2
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0890-FK_ToscaServiceTemplate_policyTypesName.sql2
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0900-FK_ToscaServiceTemplate_relationshipTypesName.sql2
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0910-FK_ToscaTopologyTemplate_nodeTemplatesName.sql2
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0920-FK_ToscaTopologyTemplate_policyName.sql2
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0930-IDX_TSIDX1.sql (renamed from policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1040-IDX_TSIDX1.sql)4
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0940-PdpPolicyStatus_PdpGroup.sql (renamed from policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1050-PdpPolicyStatus_PdpGroup.sql)4
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0950-TscaServiceTemplatetopologyTemplateParentLocalName.sql (renamed from policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0930-TscaServiceTemplatetopologyTemplateParentLocalName.sql)2
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0960-FK_ToscaNodeTemplate_capabilitiesName.sql (renamed from policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1030-FK_ToscaTopologyTemplate_policyName.sql)2
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0970-FK_ToscaNodeTemplate_requirementsName.sql (renamed from policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0960-FK_ToscaNodeType_requirementsName.sql)2
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0970-FK_ToscaServiceTemplate_capabilityTypesName.sql24
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0980-FK_ToscaNodeType_requirementsName.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0980-FK_ToscaServiceTemplate_dataTypesName.sql24
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0990-FK_ToscaServiceTemplate_capabilityTypesName.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0990-FK_ToscaServiceTemplate_nodeTypesName.sql24
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1000-FK_ToscaServiceTemplate_dataTypesName.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1000-FK_ToscaServiceTemplate_policyTypesName.sql24
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1010-FK_ToscaServiceTemplate_nodeTypesName.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1010-FK_ToscaServiceTemplate_relationshipTypesName.sql24
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1020-FK_ToscaServiceTemplate_policyTypesName.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1020-FK_ToscaTopologyTemplate_nodeTemplatesName.sql24
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1030-FK_ToscaServiceTemplate_relationshipTypesName.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1030-FK_ToscaTopologyTemplate_policyName.sql24
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1040-FK_ToscaTopologyTemplate_nodeTemplatesName.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1050-FK_ToscaTopologyTemplate_policyName.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1060-TscaServiceTemplatetopologyTemplateParentLocalName.sql6
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0830-FK_ToscaNodeTemplate_capabilitiesName.sql2
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0840-FK_ToscaNodeTemplate_requirementsName.sql2
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0850-FK_ToscaNodeType_requirementsName.sql2
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0860-FK_ToscaServiceTemplate_capabilityTypesName.sql2
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0870-FK_ToscaServiceTemplate_dataTypesName.sql2
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0880-FK_ToscaServiceTemplate_nodeTypesName.sql2
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0890-FK_ToscaServiceTemplate_policyTypesName.sql2
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0900-FK_ToscaServiceTemplate_relationshipTypesName.sql2
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0910-FK_ToscaTopologyTemplate_nodeTemplatesName.sql2
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0920-FK_ToscaTopologyTemplate_policyName.sql2
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0930-IDX_TSIDX1.sql (renamed from policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1040-IDX_TSIDX1.sql)0
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0930-TscaServiceTemplatetopologyTemplateParentLocalName.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0940-FK_ToscaNodeTemplate_capabilitiesName.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0940-PdpPolicyStatus_PdpGroup.sql (renamed from policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1050-PdpPolicyStatus_PdpGroup.sql)0
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0950-FK_ToscaNodeTemplate_requirementsName.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0950-TscaServiceTemplatetopologyTemplateParentLocalName.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0960-FK_ToscaNodeTemplate_capabilitiesName.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0970-FK_ToscaNodeTemplate_requirementsName.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0970-FK_ToscaServiceTemplate_capabilityTypesName.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0980-FK_ToscaNodeType_requirementsName.sql (renamed from policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0950-FK_ToscaNodeTemplate_requirementsName.sql)6
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0980-FK_ToscaServiceTemplate_dataTypesName.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0990-FK_ToscaServiceTemplate_capabilityTypesName.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0990-FK_ToscaServiceTemplate_nodeTypesName.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1000-FK_ToscaServiceTemplate_dataTypesName.sql (renamed from policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0960-FK_ToscaNodeType_requirementsName.sql)6
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1000-FK_ToscaServiceTemplate_policyTypesName.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1010-FK_ToscaServiceTemplate_nodeTypesName.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1010-FK_ToscaServiceTemplate_relationshipTypesName.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1020-FK_ToscaServiceTemplate_policyTypesName.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1020-FK_ToscaTopologyTemplate_nodeTemplatesName.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1030-FK_ToscaServiceTemplate_relationshipTypesName.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1040-FK_ToscaTopologyTemplate_nodeTemplatesName.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1050-FK_ToscaTopologyTemplate_policyName.sql (renamed from policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0940-FK_ToscaNodeTemplate_capabilitiesName.sql)6
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1060-TscaServiceTemplatetopologyTemplateParentLocalName.sql2
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0120-JpaPolicyAuditIndex_timestamp.sql4
-rw-r--r--policy-db-migrator/src/main/docker/db-migrator171
66 files changed, 506 insertions, 419 deletions
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0830-FK_ToscaNodeTemplate_capabilitiesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0830-FK_ToscaNodeTemplate_capabilitiesName.sql
index fa180f20..d4310729 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0830-FK_ToscaNodeTemplate_capabilitiesName.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0830-FK_ToscaNodeTemplate_capabilitiesName.sql
@@ -1,4 +1,4 @@
-/*
+ /*
* ============LICENSE_START=======================================================
* Copyright (C) 2021 Nordix Foundation
* ================================================================================
@@ -17,4 +17,4 @@
* ============LICENSE_END=========================================================
*/
-ALTER TABLE toscanodetemplate DROP CONSTRAINT FK_ToscaNodeTemplate_capabilitiesName;
+DROP INDEX FK_ToscaNodeTemplate_capabilitiesName ON toscanodetemplate;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0840-FK_ToscaNodeTemplate_requirementsName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0840-FK_ToscaNodeTemplate_requirementsName.sql
index 7677f001..b6bf0c08 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0840-FK_ToscaNodeTemplate_requirementsName.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0840-FK_ToscaNodeTemplate_requirementsName.sql
@@ -17,4 +17,4 @@
* ============LICENSE_END=========================================================
*/
-ALTER TABLE toscanodetemplate DROP CONSTRAINT FK_ToscaNodeTemplate_requirementsName;
+DROP INDEX FK_ToscaNodeTemplate_requirementsName ON toscanodetemplate;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0850-FK_ToscaNodeType_requirementsName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0850-FK_ToscaNodeType_requirementsName.sql
index 29e7ba60..2d0f6d41 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0850-FK_ToscaNodeType_requirementsName.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0850-FK_ToscaNodeType_requirementsName.sql
@@ -17,4 +17,4 @@
* ============LICENSE_END=========================================================
*/
-ALTER TABLE toscanodetype DROP CONSTRAINT FK_ToscaNodeType_requirementsName;
+DROP INDEX FK_ToscaNodeType_requirementsName ON toscanodetype;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0860-FK_ToscaServiceTemplate_capabilityTypesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0860-FK_ToscaServiceTemplate_capabilityTypesName.sql
index 4a13c709..860b1703 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0860-FK_ToscaServiceTemplate_capabilityTypesName.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0860-FK_ToscaServiceTemplate_capabilityTypesName.sql
@@ -17,4 +17,4 @@
* ============LICENSE_END=========================================================
*/
-ALTER TABLE toscaservicetemplate DROP CONSTRAINT FK_ToscaServiceTemplate_capabilityTypesName;
+DROP INDEX FK_ToscaServiceTemplate_capabilityTypesName ON toscaservicetemplate;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0870-FK_ToscaServiceTemplate_dataTypesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0870-FK_ToscaServiceTemplate_dataTypesName.sql
index 0f5f67a2..a34639cf 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0870-FK_ToscaServiceTemplate_dataTypesName.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0870-FK_ToscaServiceTemplate_dataTypesName.sql
@@ -17,4 +17,4 @@
* ============LICENSE_END=========================================================
*/
-ALTER TABLE toscaservicetemplate DROP CONSTRAINT FK_ToscaServiceTemplate_dataTypesName;
+DROP INDEX FK_ToscaServiceTemplate_dataTypesName ON toscaservicetemplate;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0880-FK_ToscaServiceTemplate_nodeTypesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0880-FK_ToscaServiceTemplate_nodeTypesName.sql
index 49ab3064..729fb460 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0880-FK_ToscaServiceTemplate_nodeTypesName.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0880-FK_ToscaServiceTemplate_nodeTypesName.sql
@@ -17,4 +17,4 @@
* ============LICENSE_END=========================================================
*/
-ALTER TABLE toscaservicetemplate DROP CONSTRAINT FK_ToscaServiceTemplate_nodeTypesName;
+DROP INDEX FK_ToscaServiceTemplate_nodeTypesName ON toscaservicetemplate;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0890-FK_ToscaServiceTemplate_policyTypesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0890-FK_ToscaServiceTemplate_policyTypesName.sql
index 63a233c6..14da31be 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0890-FK_ToscaServiceTemplate_policyTypesName.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0890-FK_ToscaServiceTemplate_policyTypesName.sql
@@ -17,4 +17,4 @@
* ============LICENSE_END=========================================================
*/
-ALTER TABLE toscaservicetemplate DROP CONSTRAINT FK_ToscaServiceTemplate_policyTypesName;
+DROP INDEX FK_ToscaServiceTemplate_policyTypesName ON toscaservicetemplate;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0900-FK_ToscaServiceTemplate_relationshipTypesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0900-FK_ToscaServiceTemplate_relationshipTypesName.sql
index eca7ac66..4bba2ba2 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0900-FK_ToscaServiceTemplate_relationshipTypesName.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0900-FK_ToscaServiceTemplate_relationshipTypesName.sql
@@ -17,4 +17,4 @@
* ============LICENSE_END=========================================================
*/
-ALTER TABLE toscaservicetemplate DROP CONSTRAINT FK_ToscaServiceTemplate_relationshipTypesName;
+DROP INDEX FK_ToscaServiceTemplate_relationshipTypesName ON toscaservicetemplate;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0910-FK_ToscaTopologyTemplate_nodeTemplatesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0910-FK_ToscaTopologyTemplate_nodeTemplatesName.sql
index 427435de..b50cb73a 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0910-FK_ToscaTopologyTemplate_nodeTemplatesName.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0910-FK_ToscaTopologyTemplate_nodeTemplatesName.sql
@@ -17,4 +17,4 @@
* ============LICENSE_END=========================================================
*/
-ALTER TABLE toscatopologytemplate DROP CONSTRAINT FK_ToscaTopologyTemplate_nodeTemplatesName;
+DROP INDEX FK_ToscaTopologyTemplate_nodeTemplatesName ON toscatopologytemplate;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0920-FK_ToscaTopologyTemplate_policyName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0920-FK_ToscaTopologyTemplate_policyName.sql
index 8d9627cc..528610a5 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0920-FK_ToscaTopologyTemplate_policyName.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0920-FK_ToscaTopologyTemplate_policyName.sql
@@ -17,4 +17,4 @@
* ============LICENSE_END=========================================================
*/
-ALTER TABLE toscatopologytemplate DROP CONSTRAINT FK_ToscaTopologyTemplate_policyName;
+DROP INDEX FK_ToscaTopologyTemplate_policyName ON toscatopologytemplate;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1040-IDX_TSIDX1.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0930-IDX_TSIDX1.sql
index 0d2d4c69..bf9927a3 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1040-IDX_TSIDX1.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0930-IDX_TSIDX1.sql
@@ -17,8 +17,4 @@
* ============LICENSE_END=========================================================
*/
-SET FOREIGN_KEY_CHECKS = 0;
-
DROP INDEX IDX_TSIDX1 ON pdpstatistics;
-
-SET FOREIGN_KEY_CHECKS = 1;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1050-PdpPolicyStatus_PdpGroup.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0940-PdpPolicyStatus_PdpGroup.sql
index 0507184e..3ab3ffee 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1050-PdpPolicyStatus_PdpGroup.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0940-PdpPolicyStatus_PdpGroup.sql
@@ -17,8 +17,4 @@
* ============LICENSE_END=========================================================
*/
-SET FOREIGN_KEY_CHECKS = 0;
-
DROP INDEX PdpPolicyStatus_PdpGroup ON pdppolicystatus;
-
-SET FOREIGN_KEY_CHECKS = 1;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0930-TscaServiceTemplatetopologyTemplateParentLocalName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0950-TscaServiceTemplatetopologyTemplateParentLocalName.sql
index 8b9f863b..843a30b2 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0930-TscaServiceTemplatetopologyTemplateParentLocalName.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0950-TscaServiceTemplatetopologyTemplateParentLocalName.sql
@@ -17,4 +17,4 @@
* ============LICENSE_END=========================================================
*/
-ALTER TABLE toscaservicetemplate DROP CONSTRAINT TscaServiceTemplatetopologyTemplateParentLocalName;
+DROP INDEX TscaServiceTemplatetopologyTemplateParentLocalName ON toscaservicetemplate;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1030-FK_ToscaTopologyTemplate_policyName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0960-FK_ToscaNodeTemplate_capabilitiesName.sql
index bd25f3a5..fa180f20 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1030-FK_ToscaTopologyTemplate_policyName.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0960-FK_ToscaNodeTemplate_capabilitiesName.sql
@@ -17,4 +17,4 @@
* ============LICENSE_END=========================================================
*/
-CREATE INDEX FK_ToscaTopologyTemplate_policyName ON toscatopologytemplate(policyName, policyVersion);
+ALTER TABLE toscanodetemplate DROP CONSTRAINT FK_ToscaNodeTemplate_capabilitiesName;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0960-FK_ToscaNodeType_requirementsName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0970-FK_ToscaNodeTemplate_requirementsName.sql
index 1ee32de8..7677f001 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0960-FK_ToscaNodeType_requirementsName.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0970-FK_ToscaNodeTemplate_requirementsName.sql
@@ -17,4 +17,4 @@
* ============LICENSE_END=========================================================
*/
-CREATE INDEX FK_ToscaNodeType_requirementsName ON toscanodetype(requirementsName, requirementsVersion);
+ALTER TABLE toscanodetemplate DROP CONSTRAINT FK_ToscaNodeTemplate_requirementsName;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0970-FK_ToscaServiceTemplate_capabilityTypesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0970-FK_ToscaServiceTemplate_capabilityTypesName.sql
deleted file mode 100644
index a7e7159d..00000000
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0970-FK_ToscaServiceTemplate_capabilityTypesName.sql
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-SET FOREIGN_KEY_CHECKS = 0;
-
-DROP INDEX FK_ToscaServiceTemplate_capabilityTypesName ON toscaservicetemplate;
-
-SET FOREIGN_KEY_CHECKS = 1;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0980-FK_ToscaNodeType_requirementsName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0980-FK_ToscaNodeType_requirementsName.sql
new file mode 100644
index 00000000..29e7ba60
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0980-FK_ToscaNodeType_requirementsName.sql
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+ALTER TABLE toscanodetype DROP CONSTRAINT FK_ToscaNodeType_requirementsName;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0980-FK_ToscaServiceTemplate_dataTypesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0980-FK_ToscaServiceTemplate_dataTypesName.sql
deleted file mode 100644
index 6d590832..00000000
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0980-FK_ToscaServiceTemplate_dataTypesName.sql
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-SET FOREIGN_KEY_CHECKS = 0;
-
-DROP INDEX FK_ToscaServiceTemplate_dataTypesName ON toscaservicetemplate;
-
-SET FOREIGN_KEY_CHECKS = 1;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0990-FK_ToscaServiceTemplate_capabilityTypesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0990-FK_ToscaServiceTemplate_capabilityTypesName.sql
new file mode 100644
index 00000000..4a13c709
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0990-FK_ToscaServiceTemplate_capabilityTypesName.sql
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+ALTER TABLE toscaservicetemplate DROP CONSTRAINT FK_ToscaServiceTemplate_capabilityTypesName;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0990-FK_ToscaServiceTemplate_nodeTypesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0990-FK_ToscaServiceTemplate_nodeTypesName.sql
deleted file mode 100644
index 49199076..00000000
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0990-FK_ToscaServiceTemplate_nodeTypesName.sql
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-SET FOREIGN_KEY_CHECKS = 0;
-
-DROP INDEX FK_ToscaServiceTemplate_nodeTypesName ON toscaservicetemplate;
-
-SET FOREIGN_KEY_CHECKS = 1;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1000-FK_ToscaServiceTemplate_dataTypesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1000-FK_ToscaServiceTemplate_dataTypesName.sql
new file mode 100644
index 00000000..0f5f67a2
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1000-FK_ToscaServiceTemplate_dataTypesName.sql
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+ALTER TABLE toscaservicetemplate DROP CONSTRAINT FK_ToscaServiceTemplate_dataTypesName;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1000-FK_ToscaServiceTemplate_policyTypesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1000-FK_ToscaServiceTemplate_policyTypesName.sql
deleted file mode 100644
index 970669ac..00000000
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1000-FK_ToscaServiceTemplate_policyTypesName.sql
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-SET FOREIGN_KEY_CHECKS = 0;
-
-DROP INDEX FK_ToscaServiceTemplate_policyTypesName ON toscaservicetemplate;
-
-SET FOREIGN_KEY_CHECKS = 1;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1010-FK_ToscaServiceTemplate_nodeTypesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1010-FK_ToscaServiceTemplate_nodeTypesName.sql
new file mode 100644
index 00000000..49ab3064
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1010-FK_ToscaServiceTemplate_nodeTypesName.sql
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+ALTER TABLE toscaservicetemplate DROP CONSTRAINT FK_ToscaServiceTemplate_nodeTypesName;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1010-FK_ToscaServiceTemplate_relationshipTypesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1010-FK_ToscaServiceTemplate_relationshipTypesName.sql
deleted file mode 100644
index b43d4142..00000000
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1010-FK_ToscaServiceTemplate_relationshipTypesName.sql
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-SET FOREIGN_KEY_CHECKS = 0;
-
-DROP INDEX FK_ToscaServiceTemplate_relationshipTypesName ON toscaservicetemplate;
-
-SET FOREIGN_KEY_CHECKS = 1;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1020-FK_ToscaServiceTemplate_policyTypesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1020-FK_ToscaServiceTemplate_policyTypesName.sql
new file mode 100644
index 00000000..63a233c6
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1020-FK_ToscaServiceTemplate_policyTypesName.sql
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+ALTER TABLE toscaservicetemplate DROP CONSTRAINT FK_ToscaServiceTemplate_policyTypesName;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1020-FK_ToscaTopologyTemplate_nodeTemplatesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1020-FK_ToscaTopologyTemplate_nodeTemplatesName.sql
deleted file mode 100644
index c8aa8e6b..00000000
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1020-FK_ToscaTopologyTemplate_nodeTemplatesName.sql
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-SET FOREIGN_KEY_CHECKS = 0;
-
-DROP INDEX FK_ToscaTopologyTemplate_nodeTemplatesName ON toscatopologytemplate;
-
-SET FOREIGN_KEY_CHECKS = 1;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1030-FK_ToscaServiceTemplate_relationshipTypesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1030-FK_ToscaServiceTemplate_relationshipTypesName.sql
new file mode 100644
index 00000000..eca7ac66
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1030-FK_ToscaServiceTemplate_relationshipTypesName.sql
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+ALTER TABLE toscaservicetemplate DROP CONSTRAINT FK_ToscaServiceTemplate_relationshipTypesName;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1030-FK_ToscaTopologyTemplate_policyName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1030-FK_ToscaTopologyTemplate_policyName.sql
deleted file mode 100644
index e0b73a2e..00000000
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1030-FK_ToscaTopologyTemplate_policyName.sql
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-SET FOREIGN_KEY_CHECKS = 0;
-
-DROP INDEX FK_ToscaTopologyTemplate_policyName ON toscatopologytemplate;
-
-SET FOREIGN_KEY_CHECKS = 1;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1040-FK_ToscaTopologyTemplate_nodeTemplatesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1040-FK_ToscaTopologyTemplate_nodeTemplatesName.sql
new file mode 100644
index 00000000..427435de
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1040-FK_ToscaTopologyTemplate_nodeTemplatesName.sql
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+ALTER TABLE toscatopologytemplate DROP CONSTRAINT FK_ToscaTopologyTemplate_nodeTemplatesName;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1050-FK_ToscaTopologyTemplate_policyName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1050-FK_ToscaTopologyTemplate_policyName.sql
new file mode 100644
index 00000000..8d9627cc
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1050-FK_ToscaTopologyTemplate_policyName.sql
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+ALTER TABLE toscatopologytemplate DROP CONSTRAINT FK_ToscaTopologyTemplate_policyName;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1060-TscaServiceTemplatetopologyTemplateParentLocalName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1060-TscaServiceTemplatetopologyTemplateParentLocalName.sql
index 96ddf0ed..8b9f863b 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1060-TscaServiceTemplatetopologyTemplateParentLocalName.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/1060-TscaServiceTemplatetopologyTemplateParentLocalName.sql
@@ -17,8 +17,4 @@
* ============LICENSE_END=========================================================
*/
-SET FOREIGN_KEY_CHECKS = 0;
-
-DROP INDEX TscaServiceTemplatetopologyTemplateParentLocalName ON toscaservicetemplate;
-
-SET FOREIGN_KEY_CHECKS = 1;
+ALTER TABLE toscaservicetemplate DROP CONSTRAINT TscaServiceTemplatetopologyTemplateParentLocalName;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0830-FK_ToscaNodeTemplate_capabilitiesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0830-FK_ToscaNodeTemplate_capabilitiesName.sql
index d96393d7..e3597b48 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0830-FK_ToscaNodeTemplate_capabilitiesName.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0830-FK_ToscaNodeTemplate_capabilitiesName.sql
@@ -17,4 +17,4 @@
* ============LICENSE_END=========================================================
*/
-ALTER TABLE toscanodetemplate ADD CONSTRAINT FK_ToscaNodeTemplate_capabilitiesName FOREIGN KEY (capabilitiesName, capabilitiesVersion) REFERENCES toscacapabilityassignments (name, version) ON UPDATE RESTRICT ON DELETE RESTRICT;
+CREATE INDEX FK_ToscaNodeTemplate_capabilitiesName ON toscanodetemplate(capabilitiesName, capabilitiesVersion);
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0840-FK_ToscaNodeTemplate_requirementsName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0840-FK_ToscaNodeTemplate_requirementsName.sql
index 491a6b70..06c389c1 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0840-FK_ToscaNodeTemplate_requirementsName.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0840-FK_ToscaNodeTemplate_requirementsName.sql
@@ -17,4 +17,4 @@
* ============LICENSE_END=========================================================
*/
-ALTER TABLE toscanodetemplate ADD CONSTRAINT FK_ToscaNodeTemplate_requirementsName FOREIGN KEY (requirementsName, requirementsVersion) REFERENCES toscarequirements (name, version) ON UPDATE RESTRICT ON DELETE RESTRICT;
+CREATE INDEX FK_ToscaNodeTemplate_requirementsName ON toscanodetemplate(requirementsName, requirementsVersion);
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0850-FK_ToscaNodeType_requirementsName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0850-FK_ToscaNodeType_requirementsName.sql
index c6f37f5c..1ee32de8 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0850-FK_ToscaNodeType_requirementsName.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0850-FK_ToscaNodeType_requirementsName.sql
@@ -17,4 +17,4 @@
* ============LICENSE_END=========================================================
*/
-ALTER TABLE toscanodetype ADD CONSTRAINT FK_ToscaNodeType_requirementsName FOREIGN KEY (requirementsName, requirementsVersion) REFERENCES toscarequirements (name, version) ON UPDATE RESTRICT ON DELETE RESTRICT;
+CREATE INDEX FK_ToscaNodeType_requirementsName ON toscanodetype(requirementsName, requirementsVersion);
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0860-FK_ToscaServiceTemplate_capabilityTypesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0860-FK_ToscaServiceTemplate_capabilityTypesName.sql
index 2942032d..89d0a95f 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0860-FK_ToscaServiceTemplate_capabilityTypesName.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0860-FK_ToscaServiceTemplate_capabilityTypesName.sql
@@ -17,4 +17,4 @@
* ============LICENSE_END=========================================================
*/
-ALTER TABLE toscaservicetemplate ADD CONSTRAINT FK_ToscaServiceTemplate_capabilityTypesName FOREIGN KEY (capabilityTypesName, capabilityTypesVersion) REFERENCES toscacapabilitytypes (name, version) ON UPDATE RESTRICT ON DELETE RESTRICT;
+CREATE INDEX FK_ToscaServiceTemplate_capabilityTypesName ON toscaservicetemplate(capabilityTypesName, capabilityTypesVersion);
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0870-FK_ToscaServiceTemplate_dataTypesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0870-FK_ToscaServiceTemplate_dataTypesName.sql
index 42d1b16d..23b1d8ca 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0870-FK_ToscaServiceTemplate_dataTypesName.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0870-FK_ToscaServiceTemplate_dataTypesName.sql
@@ -17,4 +17,4 @@
* ============LICENSE_END=========================================================
*/
-ALTER TABLE toscaservicetemplate ADD CONSTRAINT FK_ToscaServiceTemplate_dataTypesName FOREIGN KEY (dataTypesName, dataTypesVersion) REFERENCES toscadatatypes (name, version) ON UPDATE RESTRICT ON DELETE RESTRICT;
+CREATE INDEX FK_ToscaServiceTemplate_dataTypesName ON toscaservicetemplate(dataTypesName, dataTypesVersion);
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0880-FK_ToscaServiceTemplate_nodeTypesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0880-FK_ToscaServiceTemplate_nodeTypesName.sql
index ff40a80f..b8701265 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0880-FK_ToscaServiceTemplate_nodeTypesName.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0880-FK_ToscaServiceTemplate_nodeTypesName.sql
@@ -17,4 +17,4 @@
* ============LICENSE_END=========================================================
*/
-ALTER TABLE toscaservicetemplate ADD CONSTRAINT FK_ToscaServiceTemplate_nodeTypesName FOREIGN KEY (nodeTypesName, nodeTypesVersion) REFERENCES toscanodetypes (name, version) ON UPDATE RESTRICT ON DELETE RESTRICT;
+CREATE INDEX FK_ToscaServiceTemplate_nodeTypesName ON toscaservicetemplate(nodeTypesName, nodeTypesVersion);
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0890-FK_ToscaServiceTemplate_policyTypesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0890-FK_ToscaServiceTemplate_policyTypesName.sql
index ac0aad0c..247cd817 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0890-FK_ToscaServiceTemplate_policyTypesName.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0890-FK_ToscaServiceTemplate_policyTypesName.sql
@@ -17,4 +17,4 @@
* ============LICENSE_END=========================================================
*/
-ALTER TABLE toscaservicetemplate ADD CONSTRAINT FK_ToscaServiceTemplate_policyTypesName FOREIGN KEY (policyTypesName, policyTypesVersion) REFERENCES toscapolicytypes (name, version) ON UPDATE RESTRICT ON DELETE RESTRICT;
+CREATE INDEX FK_ToscaServiceTemplate_policyTypesName ON toscaservicetemplate(policyTypesName, policyTypesVersion);
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0900-FK_ToscaServiceTemplate_relationshipTypesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0900-FK_ToscaServiceTemplate_relationshipTypesName.sql
index a7526670..f9ca8b99 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0900-FK_ToscaServiceTemplate_relationshipTypesName.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0900-FK_ToscaServiceTemplate_relationshipTypesName.sql
@@ -17,4 +17,4 @@
* ============LICENSE_END=========================================================
*/
-ALTER TABLE toscaservicetemplate ADD CONSTRAINT FK_ToscaServiceTemplate_relationshipTypesName FOREIGN KEY (relationshipTypesName, relationshipTypesVersion) REFERENCES toscarelationshiptypes (name, version) ON UPDATE RESTRICT ON DELETE RESTRICT;
+CREATE INDEX FK_ToscaServiceTemplate_relationshipTypesName ON toscaservicetemplate(relationshipTypesName, relationshipTypesVersion);
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0910-FK_ToscaTopologyTemplate_nodeTemplatesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0910-FK_ToscaTopologyTemplate_nodeTemplatesName.sql
index 97bf345d..b538f8ee 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0910-FK_ToscaTopologyTemplate_nodeTemplatesName.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0910-FK_ToscaTopologyTemplate_nodeTemplatesName.sql
@@ -17,4 +17,4 @@
* ============LICENSE_END=========================================================
*/
-ALTER TABLE toscatopologytemplate ADD CONSTRAINT FK_ToscaTopologyTemplate_nodeTemplatesName FOREIGN KEY (nodeTemplatesName, nodeTemplatessVersion) REFERENCES toscanodetemplates (name, version) ON UPDATE RESTRICT ON DELETE RESTRICT;
+CREATE INDEX FK_ToscaTopologyTemplate_nodeTemplatesName ON toscatopologytemplate(nodeTemplatesName, nodeTemplatessVersion);
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0920-FK_ToscaTopologyTemplate_policyName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0920-FK_ToscaTopologyTemplate_policyName.sql
index 3a973499..bd25f3a5 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0920-FK_ToscaTopologyTemplate_policyName.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0920-FK_ToscaTopologyTemplate_policyName.sql
@@ -17,4 +17,4 @@
* ============LICENSE_END=========================================================
*/
-ALTER TABLE toscatopologytemplate ADD CONSTRAINT FK_ToscaTopologyTemplate_policyName FOREIGN KEY (policyName, policyVersion) REFERENCES toscapolicies (name, version) ON UPDATE RESTRICT ON DELETE RESTRICT;
+CREATE INDEX FK_ToscaTopologyTemplate_policyName ON toscatopologytemplate(policyName, policyVersion);
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1040-IDX_TSIDX1.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0930-IDX_TSIDX1.sql
index ba63f55c..ba63f55c 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1040-IDX_TSIDX1.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0930-IDX_TSIDX1.sql
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0930-TscaServiceTemplatetopologyTemplateParentLocalName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0930-TscaServiceTemplatetopologyTemplateParentLocalName.sql
deleted file mode 100644
index ca03af86..00000000
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0930-TscaServiceTemplatetopologyTemplateParentLocalName.sql
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-ALTER TABLE toscaservicetemplate ADD CONSTRAINT TscaServiceTemplatetopologyTemplateParentLocalName FOREIGN KEY (topologyTemplateParentLocalName, topologyTemplateLocalName, topologyTemplateParentKeyVersion, topologyTemplateParentKeyName) REFERENCES toscatopologytemplate (parentLocalName, localName, parentKeyVersion, parentKeyName) ON UPDATE RESTRICT ON DELETE RESTRICT;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0940-FK_ToscaNodeTemplate_capabilitiesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0940-FK_ToscaNodeTemplate_capabilitiesName.sql
deleted file mode 100644
index e3597b48..00000000
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0940-FK_ToscaNodeTemplate_capabilitiesName.sql
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-CREATE INDEX FK_ToscaNodeTemplate_capabilitiesName ON toscanodetemplate(capabilitiesName, capabilitiesVersion);
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1050-PdpPolicyStatus_PdpGroup.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0940-PdpPolicyStatus_PdpGroup.sql
index d16c3ced..d16c3ced 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1050-PdpPolicyStatus_PdpGroup.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0940-PdpPolicyStatus_PdpGroup.sql
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0950-FK_ToscaNodeTemplate_requirementsName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0950-FK_ToscaNodeTemplate_requirementsName.sql
deleted file mode 100644
index 06c389c1..00000000
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0950-FK_ToscaNodeTemplate_requirementsName.sql
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-CREATE INDEX FK_ToscaNodeTemplate_requirementsName ON toscanodetemplate(requirementsName, requirementsVersion);
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0950-TscaServiceTemplatetopologyTemplateParentLocalName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0950-TscaServiceTemplatetopologyTemplateParentLocalName.sql
new file mode 100644
index 00000000..0fe51970
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0950-TscaServiceTemplatetopologyTemplateParentLocalName.sql
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+CREATE INDEX TscaServiceTemplatetopologyTemplateParentLocalName ON toscaservicetemplate(topologyTemplateParentLocalName, topologyTemplateLocalName, topologyTemplateParentKeyVersion, topologyTemplateParentKeyName);
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0960-FK_ToscaNodeTemplate_capabilitiesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0960-FK_ToscaNodeTemplate_capabilitiesName.sql
new file mode 100644
index 00000000..d96393d7
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0960-FK_ToscaNodeTemplate_capabilitiesName.sql
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+ALTER TABLE toscanodetemplate ADD CONSTRAINT FK_ToscaNodeTemplate_capabilitiesName FOREIGN KEY (capabilitiesName, capabilitiesVersion) REFERENCES toscacapabilityassignments (name, version) ON UPDATE RESTRICT ON DELETE RESTRICT;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0970-FK_ToscaNodeTemplate_requirementsName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0970-FK_ToscaNodeTemplate_requirementsName.sql
new file mode 100644
index 00000000..491a6b70
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0970-FK_ToscaNodeTemplate_requirementsName.sql
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+ALTER TABLE toscanodetemplate ADD CONSTRAINT FK_ToscaNodeTemplate_requirementsName FOREIGN KEY (requirementsName, requirementsVersion) REFERENCES toscarequirements (name, version) ON UPDATE RESTRICT ON DELETE RESTRICT;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0970-FK_ToscaServiceTemplate_capabilityTypesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0970-FK_ToscaServiceTemplate_capabilityTypesName.sql
deleted file mode 100644
index 89d0a95f..00000000
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0970-FK_ToscaServiceTemplate_capabilityTypesName.sql
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-CREATE INDEX FK_ToscaServiceTemplate_capabilityTypesName ON toscaservicetemplate(capabilityTypesName, capabilityTypesVersion);
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0950-FK_ToscaNodeTemplate_requirementsName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0980-FK_ToscaNodeType_requirementsName.sql
index eae64df9..c6f37f5c 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0950-FK_ToscaNodeTemplate_requirementsName.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0980-FK_ToscaNodeType_requirementsName.sql
@@ -17,8 +17,4 @@
* ============LICENSE_END=========================================================
*/
-SET FOREIGN_KEY_CHECKS = 0;
-
-DROP INDEX FK_ToscaNodeTemplate_requirementsName ON toscanodetemplate;
-
-SET FOREIGN_KEY_CHECKS = 1;
+ALTER TABLE toscanodetype ADD CONSTRAINT FK_ToscaNodeType_requirementsName FOREIGN KEY (requirementsName, requirementsVersion) REFERENCES toscarequirements (name, version) ON UPDATE RESTRICT ON DELETE RESTRICT;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0980-FK_ToscaServiceTemplate_dataTypesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0980-FK_ToscaServiceTemplate_dataTypesName.sql
deleted file mode 100644
index 23b1d8ca..00000000
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0980-FK_ToscaServiceTemplate_dataTypesName.sql
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-CREATE INDEX FK_ToscaServiceTemplate_dataTypesName ON toscaservicetemplate(dataTypesName, dataTypesVersion);
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0990-FK_ToscaServiceTemplate_capabilityTypesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0990-FK_ToscaServiceTemplate_capabilityTypesName.sql
new file mode 100644
index 00000000..2942032d
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0990-FK_ToscaServiceTemplate_capabilityTypesName.sql
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+ALTER TABLE toscaservicetemplate ADD CONSTRAINT FK_ToscaServiceTemplate_capabilityTypesName FOREIGN KEY (capabilityTypesName, capabilityTypesVersion) REFERENCES toscacapabilitytypes (name, version) ON UPDATE RESTRICT ON DELETE RESTRICT;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0990-FK_ToscaServiceTemplate_nodeTypesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0990-FK_ToscaServiceTemplate_nodeTypesName.sql
deleted file mode 100644
index b8701265..00000000
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/0990-FK_ToscaServiceTemplate_nodeTypesName.sql
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-CREATE INDEX FK_ToscaServiceTemplate_nodeTypesName ON toscaservicetemplate(nodeTypesName, nodeTypesVersion);
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0960-FK_ToscaNodeType_requirementsName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1000-FK_ToscaServiceTemplate_dataTypesName.sql
index 6854e12f..42d1b16d 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0960-FK_ToscaNodeType_requirementsName.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1000-FK_ToscaServiceTemplate_dataTypesName.sql
@@ -17,8 +17,4 @@
* ============LICENSE_END=========================================================
*/
-SET FOREIGN_KEY_CHECKS = 0;
-
-DROP INDEX FK_ToscaNodeType_requirementsName ON toscanodetype;
-
-SET FOREIGN_KEY_CHECKS = 1;
+ALTER TABLE toscaservicetemplate ADD CONSTRAINT FK_ToscaServiceTemplate_dataTypesName FOREIGN KEY (dataTypesName, dataTypesVersion) REFERENCES toscadatatypes (name, version) ON UPDATE RESTRICT ON DELETE RESTRICT;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1000-FK_ToscaServiceTemplate_policyTypesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1000-FK_ToscaServiceTemplate_policyTypesName.sql
deleted file mode 100644
index 247cd817..00000000
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1000-FK_ToscaServiceTemplate_policyTypesName.sql
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-CREATE INDEX FK_ToscaServiceTemplate_policyTypesName ON toscaservicetemplate(policyTypesName, policyTypesVersion);
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1010-FK_ToscaServiceTemplate_nodeTypesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1010-FK_ToscaServiceTemplate_nodeTypesName.sql
new file mode 100644
index 00000000..ff40a80f
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1010-FK_ToscaServiceTemplate_nodeTypesName.sql
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+ALTER TABLE toscaservicetemplate ADD CONSTRAINT FK_ToscaServiceTemplate_nodeTypesName FOREIGN KEY (nodeTypesName, nodeTypesVersion) REFERENCES toscanodetypes (name, version) ON UPDATE RESTRICT ON DELETE RESTRICT;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1010-FK_ToscaServiceTemplate_relationshipTypesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1010-FK_ToscaServiceTemplate_relationshipTypesName.sql
deleted file mode 100644
index f9ca8b99..00000000
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1010-FK_ToscaServiceTemplate_relationshipTypesName.sql
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-CREATE INDEX FK_ToscaServiceTemplate_relationshipTypesName ON toscaservicetemplate(relationshipTypesName, relationshipTypesVersion);
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1020-FK_ToscaServiceTemplate_policyTypesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1020-FK_ToscaServiceTemplate_policyTypesName.sql
new file mode 100644
index 00000000..ac0aad0c
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1020-FK_ToscaServiceTemplate_policyTypesName.sql
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+ALTER TABLE toscaservicetemplate ADD CONSTRAINT FK_ToscaServiceTemplate_policyTypesName FOREIGN KEY (policyTypesName, policyTypesVersion) REFERENCES toscapolicytypes (name, version) ON UPDATE RESTRICT ON DELETE RESTRICT;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1020-FK_ToscaTopologyTemplate_nodeTemplatesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1020-FK_ToscaTopologyTemplate_nodeTemplatesName.sql
deleted file mode 100644
index b538f8ee..00000000
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1020-FK_ToscaTopologyTemplate_nodeTemplatesName.sql
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-CREATE INDEX FK_ToscaTopologyTemplate_nodeTemplatesName ON toscatopologytemplate(nodeTemplatesName, nodeTemplatessVersion);
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1030-FK_ToscaServiceTemplate_relationshipTypesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1030-FK_ToscaServiceTemplate_relationshipTypesName.sql
new file mode 100644
index 00000000..a7526670
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1030-FK_ToscaServiceTemplate_relationshipTypesName.sql
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+ALTER TABLE toscaservicetemplate ADD CONSTRAINT FK_ToscaServiceTemplate_relationshipTypesName FOREIGN KEY (relationshipTypesName, relationshipTypesVersion) REFERENCES toscarelationshiptypes (name, version) ON UPDATE RESTRICT ON DELETE RESTRICT;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1040-FK_ToscaTopologyTemplate_nodeTemplatesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1040-FK_ToscaTopologyTemplate_nodeTemplatesName.sql
new file mode 100644
index 00000000..97bf345d
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1040-FK_ToscaTopologyTemplate_nodeTemplatesName.sql
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+ALTER TABLE toscatopologytemplate ADD CONSTRAINT FK_ToscaTopologyTemplate_nodeTemplatesName FOREIGN KEY (nodeTemplatesName, nodeTemplatessVersion) REFERENCES toscanodetemplates (name, version) ON UPDATE RESTRICT ON DELETE RESTRICT;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0940-FK_ToscaNodeTemplate_capabilitiesName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1050-FK_ToscaTopologyTemplate_policyName.sql
index 60b08a58..3a973499 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/downgrade/0940-FK_ToscaNodeTemplate_capabilitiesName.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1050-FK_ToscaTopologyTemplate_policyName.sql
@@ -17,8 +17,4 @@
* ============LICENSE_END=========================================================
*/
-SET FOREIGN_KEY_CHECKS = 0;
-
-DROP INDEX FK_ToscaNodeTemplate_capabilitiesName ON toscanodetemplate;
-
-SET FOREIGN_KEY_CHECKS = 1;
+ALTER TABLE toscatopologytemplate ADD CONSTRAINT FK_ToscaTopologyTemplate_policyName FOREIGN KEY (policyName, policyVersion) REFERENCES toscapolicies (name, version) ON UPDATE RESTRICT ON DELETE RESTRICT;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1060-TscaServiceTemplatetopologyTemplateParentLocalName.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1060-TscaServiceTemplatetopologyTemplateParentLocalName.sql
index 0fe51970..ca03af86 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1060-TscaServiceTemplatetopologyTemplateParentLocalName.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0800/upgrade/1060-TscaServiceTemplatetopologyTemplateParentLocalName.sql
@@ -17,4 +17,4 @@
* ============LICENSE_END=========================================================
*/
-CREATE INDEX TscaServiceTemplatetopologyTemplateParentLocalName ON toscaservicetemplate(topologyTemplateParentLocalName, topologyTemplateLocalName, topologyTemplateParentKeyVersion, topologyTemplateParentKeyName);
+ALTER TABLE toscaservicetemplate ADD CONSTRAINT TscaServiceTemplatetopologyTemplateParentLocalName FOREIGN KEY (topologyTemplateParentLocalName, topologyTemplateLocalName, topologyTemplateParentKeyVersion, topologyTemplateParentKeyName) REFERENCES toscatopologytemplate (parentLocalName, localName, parentKeyVersion, parentKeyName) ON UPDATE RESTRICT ON DELETE RESTRICT;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0120-JpaPolicyAuditIndex_timestamp.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0120-JpaPolicyAuditIndex_timestamp.sql
index 275d3b10..8b94f2df 100644
--- a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0120-JpaPolicyAuditIndex_timestamp.sql
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0120-JpaPolicyAuditIndex_timestamp.sql
@@ -17,8 +17,4 @@
* ============LICENSE_END=========================================================
*/
-SET FOREIGN_KEY_CHECKS = 0;
-
DROP INDEX JpaPolicyAuditIndex_timestamp ON jpapolicyaudit;
-
-SET FOREIGN_KEY_CHECKS = 1;
diff --git a/policy-db-migrator/src/main/docker/db-migrator b/policy-db-migrator/src/main/docker/db-migrator
index 7eced0e5..d66797c1 100644
--- a/policy-db-migrator/src/main/docker/db-migrator
+++ b/policy-db-migrator/src/main/docker/db-migrator
@@ -324,6 +324,87 @@ function previous_release
}
#####################################################
+# 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
+#####################################################
+
+function last_operation_status
+{
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- last_operation_status --"
+ set -x
+ fi
+
+ local query rc row
+
+ query="SELECT script, operation, from_version, to_version, success FROM "
+ query=${query}"${METADATA_HISTORY} WHERE id="
+ query=${query}"(SELECT MAX(id) from ${METADATA_HISTORY}) "
+ query=${query}"AND success=0"
+
+ row=$(${MYSQL} --skip-column-names --silent --execute "${query}")
+
+ if [ "${row}" != "" ]; then
+ LAST_SCRIPT=$(echo $row | awk '{print $1}')
+ LAST_OPERATION=$(echo $row | awk '{print $2}')
+ LAST_FROM_VERSION=$(echo $row | awk '{print $3}')
+ LAST_TO_VERSION=$(echo $row | awk '{print $4}')
+ LAST_STATUS=$(echo $row | awk '{print $5}')
+ rc=0
+ else
+ rc=1
+ fi
+
+ return $rc;
+}
+
+#####################################################
# execute sql script history
#####################################################
@@ -387,10 +468,28 @@ function upgrade
set -x
fi
- local sqlName sqlFile schemaVersion upgradeSqls rc tagDate tag
+ local sqlName sqlFile schemaVersion upgradeSqls rc tagDate tag retry compare
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)
@@ -401,12 +500,25 @@ function upgrade
if [ "${schemaVersion}" -gt "${CURRENT_RELEASE}" ] && \
[ "${schemaVersion}" -le "${TARGET_UPGRADE_RELEASE}" ]; then
tag=${tagDate}"${schemaVersion}u"
- 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}
+ 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
+ rc=1
+ else
+ 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
fi
fi
done
@@ -428,10 +540,28 @@ function downgrade
set -x
fi
- local sqlName sqlFile schemaVersion downgradeSqls rc tagDate tag
+ local sqlName sqlFile schemaVersion downgradeSqls rc tagDate tag retry compare
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)
@@ -441,12 +571,25 @@ function downgrade
if [ "${schemaVersion}" -le "${CURRENT_RELEASE}" ] && \
[ "${schemaVersion}" -gt "${TARGET_DOWNGRADE_RELEASE}" ]; then
tag=${tagDate}"${schemaVersion}d"
- 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}
+ 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
+ rc=1
+ else
+ 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
fi
fi
done