Update pdp_enginestats records during upgrade/downgrade 47/123547/1
authorktimoney <kevin.timoney@est.tech>
Wed, 25 Aug 2021 11:14:54 +0000 (12:14 +0100)
committerKevin Timoney <kevin.timoney@est.tech>
Wed, 25 Aug 2021 12:38:05 +0000 (12:38 +0000)
Updates to pdpstatistics have a knock on effect on pdp_enginestats.
Table data needs to updated to ensure records are in sync

Issue-ID: POLICY-3583
Change-Id: Id7408beceb47e540e933e8ccc0ff05095f8da85b
Signed-off-by: ktimoney <kevin.timoney@est.tech>
30 files changed:
policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0100-pdp.sql [moved from policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0120-pdp.sql with 100% similarity]
policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0110-idx_tsidx1.sql [moved from policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0130-idx_tsidx1.sql with 100% similarity]
policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0120-pk_pdpstatistics.sql [moved from policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0160-pk_pdpstatistics.sql with 90% similarity]
policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0130-pdpstatistics.sql [new file with mode: 0644]
policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0140-pk_pdpstatistics.sql
policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0150-pdpstatistics.sql
policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0160-jpapdpstatistics_enginestats.sql [moved from policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0110-jpapdpstatistics_enginestats.sql with 100% similarity]
policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0170-jpapdpstatistics_enginestats.sql [new file with mode: 0644]
policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0170-pdpstatistics.sql [deleted file]
policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0180-jpapdpstatistics_enginestats.sql [moved from policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0100-jpapdpstatistics_enginestats.sql with 100% similarity]
policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0190-jpapolicyaudit.sql [moved from policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0180-jpapolicyaudit.sql with 100% similarity]
policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0200-JpaPolicyAuditIndex_timestamp.sql [moved from policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0190-JpaPolicyAuditIndex_timestamp.sql with 100% similarity]
policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0210-sequence.sql
policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0220-sequence.sql [moved from policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0200-sequence.sql with 96% similarity]
policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0100-pdp.sql [moved from policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0120-pdp.sql with 100% similarity]
policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0110-idx_tsidx1.sql [moved from policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0130-idx_tsidx1.sql with 100% similarity]
policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0120-pk_pdpstatistics.sql [new file with mode: 0644]
policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0130-pdpstatistics.sql [new file with mode: 0644]
policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0140-pk_pdpstatistics.sql
policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0150-pdpstatistics.sql
policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0160-jpapdpstatistics_enginestats.sql [moved from policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0110-jpapdpstatistics_enginestats.sql with 100% similarity]
policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0160-pk_pdpstatistics.sql [deleted file]
policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0170-jpapdpstatistics_enginestats.sql [new file with mode: 0644]
policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0170-pdpstatistics.sql [deleted file]
policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0180-jpapdpstatistics_enginestats.sql [moved from policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0100-jpapdpstatistics_enginestats.sql with 100% similarity]
policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0190-jpapolicyaudit.sql [moved from policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0180-jpapolicyaudit.sql with 100% similarity]
policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0200-JpaPolicyAuditIndex_timestamp.sql [moved from policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0190-JpaPolicyAuditIndex_timestamp.sql with 100% similarity]
policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0200-sequence.sql [deleted file]
policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0210-sequence.sql
policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0220-sequence.sql [new file with mode: 0644]

@@ -17,6 +17,4 @@
  *  ============LICENSE_END=========================================================
  */
 
-ALTER TABLE pdpstatistics DROP CONSTRAINT PRIMARY KEY;
-
-UPDATE pdpstatistics set ID = 0;
+ALTER TABLE pdpstatistics ADD CONSTRAINT PK_PDPSTATISTICS PRIMARY KEY (timeStamp, name, version);
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0130-pdpstatistics.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0130-pdpstatistics.sql
new file mode 100644 (file)
index 0000000..461f147
--- /dev/null
@@ -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 pdpstatistics DROP COLUMN POLICYUNDEPLOYCOUNT, DROP COLUMN POLICYUNDEPLOYFAILCOUNT, DROP COLUMN POLICYUNDEPLOYSUCCESSCOUNT, DROP COLUMN ID;
index b3d4767..012344b 100644 (file)
@@ -17,4 +17,6 @@
  *  ============LICENSE_END=========================================================
  */
 
-ALTER TABLE pdpstatistics ADD CONSTRAINT PK_PDPSTATISTICS PRIMARY KEY (timeStamp, name, version);
+ALTER TABLE pdpstatistics DROP CONSTRAINT PRIMARY KEY;
+
+UPDATE pdpstatistics set ID = 0;
index 461f147..4bf55e8 100644 (file)
@@ -17,4 +17,4 @@
  *  ============LICENSE_END=========================================================
  */
 
-ALTER TABLE pdpstatistics DROP COLUMN POLICYUNDEPLOYCOUNT, DROP COLUMN POLICYUNDEPLOYFAILCOUNT, DROP COLUMN POLICYUNDEPLOYSUCCESSCOUNT, DROP COLUMN ID;
+ALTER TABLE pdpstatistics MODIFY COLUMN timeStamp datetime NOT NULL;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0170-jpapdpstatistics_enginestats.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0170-jpapdpstatistics_enginestats.sql
new file mode 100644 (file)
index 0000000..7163431
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * ============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=========================================================
+ */
+UPDATE jpapdpstatistics_enginestats a
+  JOIN pdpstatistics b
+    ON a.name = b.name AND a.version = b.version AND a.id = b.id
+   SET a.timeStamp = b.timeStamp;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0170-pdpstatistics.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/downgrade/0170-pdpstatistics.sql
deleted file mode 100644 (file)
index 4bf55e8..0000000
+++ /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 pdpstatistics MODIFY COLUMN timeStamp datetime NOT NULL;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0120-pk_pdpstatistics.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0120-pk_pdpstatistics.sql
new file mode 100644 (file)
index 0000000..4066c01
--- /dev/null
@@ -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 pdpstatistics DROP PRIMARY KEY;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0130-pdpstatistics.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0130-pdpstatistics.sql
new file mode 100644 (file)
index 0000000..c4a1123
--- /dev/null
@@ -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 pdpstatistics ADD COLUMN POLICYUNDEPLOYCOUNT BIGINT DEFAULT NULL NULL AFTER POLICYEXECUTEDSUCCESSCOUNT, ADD COLUMN POLICYUNDEPLOYFAILCOUNT BIGINT DEFAULT NULL NULL, ADD COLUMN POLICYUNDEPLOYSUCCESSCOUNT BIGINT DEFAULT NULL NULL, ADD COLUMN ID BIGINT NOT NULL;
index 4066c01..b8a96b6 100644 (file)
@@ -17,4 +17,6 @@
  *  ============LICENSE_END=========================================================
  */
 
-ALTER TABLE pdpstatistics DROP PRIMARY KEY;
+UPDATE pdpstatistics as p JOIN (SELECT name, version, timeStamp, ROW_NUMBER() OVER (ORDER BY timeStamp ASC) AS row_num FROM pdpstatistics GROUP BY name, version, timeStamp) AS t ON (p.name=t.name AND p.version=t.version AND p.timeStamp = t.timeStamp) SET p.id=t.row_num;
+
+ALTER TABLE pdpstatistics ADD CONSTRAINT PK_PDPSTATISTICS PRIMARY KEY (ID, name, version);
index c4a1123..98e2699 100644 (file)
@@ -17,4 +17,4 @@
  *  ============LICENSE_END=========================================================
  */
 
-ALTER TABLE pdpstatistics ADD COLUMN POLICYUNDEPLOYCOUNT BIGINT DEFAULT NULL NULL AFTER POLICYEXECUTEDSUCCESSCOUNT, ADD COLUMN POLICYUNDEPLOYFAILCOUNT BIGINT DEFAULT NULL NULL, ADD COLUMN POLICYUNDEPLOYSUCCESSCOUNT BIGINT DEFAULT NULL NULL, ADD COLUMN ID BIGINT NOT NULL;
+ALTER TABLE pdpstatistics MODIFY COLUMN timeStamp datetime NULL;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0160-pk_pdpstatistics.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0160-pk_pdpstatistics.sql
deleted file mode 100644 (file)
index b8a96b6..0000000
+++ /dev/null
@@ -1,22 +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=========================================================
- */
-
-UPDATE pdpstatistics as p JOIN (SELECT name, version, timeStamp, ROW_NUMBER() OVER (ORDER BY timeStamp ASC) AS row_num FROM pdpstatistics GROUP BY name, version, timeStamp) AS t ON (p.name=t.name AND p.version=t.version AND p.timeStamp = t.timeStamp) SET p.id=t.row_num;
-
-ALTER TABLE pdpstatistics ADD CONSTRAINT PK_PDPSTATISTICS PRIMARY KEY (ID, name, version);
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0170-jpapdpstatistics_enginestats.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0170-jpapdpstatistics_enginestats.sql
new file mode 100644 (file)
index 0000000..ce78c34
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * ============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=========================================================
+ */
+UPDATE jpapdpstatistics_enginestats a
+  JOIN pdpstatistics b
+    ON a.name = b.name AND a.version = b.version AND a.timeStamp = b.timeStamp
+   SET a.id = b.id;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0170-pdpstatistics.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0170-pdpstatistics.sql
deleted file mode 100644 (file)
index 98e2699..0000000
+++ /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 pdpstatistics MODIFY COLUMN timeStamp datetime NULL;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0200-sequence.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0200-sequence.sql
deleted file mode 100644 (file)
index 64d6f01..0000000
+++ /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 TABLE IF NOT EXISTS sequence (SEQ_NAME VARCHAR(50) NOT NULL, SEQ_COUNT DECIMAL(38) DEFAULT NULL NULL, CONSTRAINT PK_SEQUENCE PRIMARY KEY (SEQ_NAME));
index c90905e..64d6f01 100644 (file)
@@ -17,4 +17,4 @@
  *  ============LICENSE_END=========================================================
  */
 
-INSERT INTO sequence(SEQ_NAME, SEQ_COUNT) VALUES('SEQ_GEN', (SELECT IFNULL(max(id),0) FROM pdpstatistics));
+CREATE TABLE IF NOT EXISTS sequence (SEQ_NAME VARCHAR(50) NOT NULL, SEQ_COUNT DECIMAL(38) DEFAULT NULL NULL, CONSTRAINT PK_SEQUENCE PRIMARY KEY (SEQ_NAME));
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0220-sequence.sql b/policy-db-migrator/src/main/docker/config/policyadmin/sql/0900/upgrade/0220-sequence.sql
new file mode 100644 (file)
index 0000000..c90905e
--- /dev/null
@@ -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=========================================================
+ */
+
+INSERT INTO sequence(SEQ_NAME, SEQ_COUNT) VALUES('SEQ_GEN', (SELECT IFNULL(max(id),0) FROM pdpstatistics));