Add upgrade/downgrade scripts for postgres in db-migrator 52/126852/1
authorwaynedunican <wayne.dunican@est.tech>
Tue, 11 Jan 2022 09:20:28 +0000 (09:20 +0000)
committerWayne Dunican <wayne.dunican@est.tech>
Thu, 20 Jan 2022 08:35:21 +0000 (08:35 +0000)
- Istanbul upgrade scripts
- Istanbul downgrade scripts

Issue-ID: POLICY-2715
Change-Id: I0dcfd11acaf5971581db081f2ff18b7657d0c7af
Signed-off-by: Wayne Dunican <wayne.dunican@est.tech>
26 files changed:
policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0100-pdp.sql [new file with mode: 0644]
policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0110-idx_tsidx1.sql [new file with mode: 0644]
policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0120-pk_pdpstatistics.sql [new file with mode: 0644]
policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0130-pdpstatistics.sql [new file with mode: 0644]
policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0140-pk_pdpstatistics.sql [new file with mode: 0644]
policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0150-pdpstatistics.sql [new file with mode: 0644]
policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0160-jpapdpstatistics_enginestats.sql [new file with mode: 0644]
policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0170-jpapdpstatistics_enginestats.sql [new file with mode: 0644]
policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0180-jpapdpstatistics_enginestats.sql [new file with mode: 0644]
policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0190-jpapolicyaudit.sql [new file with mode: 0644]
policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0200-JpaPolicyAuditIndex_timestamp.sql [new file with mode: 0644]
policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0210-sequence.sql [new file with mode: 0644]
policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0220-sequence.sql [new file with mode: 0644]
policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0100-pdp.sql [new file with mode: 0644]
policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0110-idx_tsidx1.sql [new file with mode: 0644]
policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0120-pk_pdpstatistics.sql [new file with mode: 0644]
policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0130-pdpstatistics.sql [new file with mode: 0644]
policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0140-pk_pdpstatistics.sql [new file with mode: 0644]
policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0150-pdpstatistics.sql [new file with mode: 0644]
policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0160-jpapdpstatistics_enginestats.sql [new file with mode: 0644]
policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0170-jpapdpstatistics_enginestats.sql [new file with mode: 0644]
policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0180-jpapdpstatistics_enginestats.sql [new file with mode: 0644]
policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0190-jpapolicyaudit.sql [new file with mode: 0644]
policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0200-JpaPolicyAuditIndex_timestamp.sql [new file with mode: 0644]
policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0210-sequence.sql [new file with mode: 0644]
policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0220-sequence.sql [new file with mode: 0644]

diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0100-pdp.sql b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0100-pdp.sql
new file mode 100644 (file)
index 0000000..fbc9c47
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 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 pdp DROP COLUMN LASTUPDATE;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0110-idx_tsidx1.sql b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0110-idx_tsidx1.sql
new file mode 100644 (file)
index 0000000..4df00a1
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 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=========================================================
+ */
+
+DROP INDEX IDX_TSIDX1;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0120-pk_pdpstatistics.sql b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0120-pk_pdpstatistics.sql
new file mode 100644 (file)
index 0000000..6542534
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 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 CONSTRAINT PK_PDPSTATISTICS PRIMARY KEY (timeStamp, name, version);
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0130-pdpstatistics.sql b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0130-pdpstatistics.sql
new file mode 100644 (file)
index 0000000..a8d021f
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 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;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0140-pk_pdpstatistics.sql b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0140-pk_pdpstatistics.sql
new file mode 100644 (file)
index 0000000..6b87eef
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 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 CONSTRAINT PRIMARY KEY;
+
+UPDATE pdpstatistics set ID = 0;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0150-pdpstatistics.sql b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0150-pdpstatistics.sql
new file mode 100644 (file)
index 0000000..17c4e6a
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 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 ALTER COLUMN timeStamp TYPE TIMESTAMP(6);
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0160-jpapdpstatistics_enginestats.sql b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0160-jpapdpstatistics_enginestats.sql
new file mode 100644 (file)
index 0000000..b2bdb43
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 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 jpapdpstatistics_enginestats DROP COLUMN ID;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0170-jpapdpstatistics_enginestats.sql b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0170-jpapdpstatistics_enginestats.sql
new file mode 100644 (file)
index 0000000..8a33f69
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 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 AS a
+SET timeStamp=b.timeStamp
+FROM pdpstatistics AS b
+WHERE a.name=b.name AND a.version=b.version AND a.id=b.id;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0180-jpapdpstatistics_enginestats.sql b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0180-jpapdpstatistics_enginestats.sql
new file mode 100644 (file)
index 0000000..114467b
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 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 jpapdpstatistics_enginestats ADD COLUMN timeStamp TIMESTAMP(6) DEFAULT NULL NULL;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0190-jpapolicyaudit.sql b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0190-jpapolicyaudit.sql
new file mode 100644 (file)
index 0000000..3a6176f
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 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=========================================================
+ */
+
+DROP TABLE IF EXISTS jpapolicyaudit;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0200-JpaPolicyAuditIndex_timestamp.sql b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0200-JpaPolicyAuditIndex_timestamp.sql
new file mode 100644 (file)
index 0000000..284ca0c
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 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=========================================================
+ */
+
+DROP INDEX IF EXISTS JpaPolicyAuditIndex_timestamp;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0210-sequence.sql b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0210-sequence.sql
new file mode 100644 (file)
index 0000000..4304348
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 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=========================================================
+ */
+
+DROP TABLE IF EXISTS sequence;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0220-sequence.sql b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0220-sequence.sql
new file mode 100644 (file)
index 0000000..f272441
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 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=========================================================
+ */
+
+DELETE from sequence;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0100-pdp.sql b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0100-pdp.sql
new file mode 100644 (file)
index 0000000..7c923d3
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 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 pdp ADD COLUMN LASTUPDATE TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0110-idx_tsidx1.sql b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0110-idx_tsidx1.sql
new file mode 100644 (file)
index 0000000..0becab7
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 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 IDX_TSIDX1 ON pdpstatistics(timeStamp, name, version);
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0120-pk_pdpstatistics.sql b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0120-pk_pdpstatistics.sql
new file mode 100644 (file)
index 0000000..c6d8d8e
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 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 CONSTRAINT pk_pdpstatistics;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0130-pdpstatistics.sql b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0130-pdpstatistics.sql
new file mode 100644 (file)
index 0000000..611a7b9
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 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, ADD COLUMN POLICYUNDEPLOYFAILCOUNT BIGINT DEFAULT NULL NULL, ADD COLUMN POLICYUNDEPLOYSUCCESSCOUNT BIGINT DEFAULT NULL NULL, ADD COLUMN ID BIGINT NOT NULL;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0140-pk_pdpstatistics.sql b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0140-pk_pdpstatistics.sql
new file mode 100644 (file)
index 0000000..86fe977
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 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 SET id=t.row_num FROM (SELECT name, version, timeStamp, ROW_NUMBER() OVER (ORDER BY timeStamp ASC) AS row_num FROM pdpstatistics GROUP BY name, version, timeStamp) AS t WHERE p.name=t.name AND p.version=t.version AND p.timeStamp=t.timeStamp;
+
+ALTER TABLE pdpstatistics ADD CONSTRAINT PK_PDPSTATISTICS PRIMARY KEY (ID, name, version);
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0150-pdpstatistics.sql b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0150-pdpstatistics.sql
new file mode 100644 (file)
index 0000000..5cf66cf
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 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 ALTER COLUMN timeStamp TIMESTAMP(6);
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0160-jpapdpstatistics_enginestats.sql b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0160-jpapdpstatistics_enginestats.sql
new file mode 100644 (file)
index 0000000..9ca423f
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 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 jpapdpstatistics_enginestats ADD COLUMN ID BIGINT DEFAULT NULL NULL;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0170-jpapdpstatistics_enginestats.sql b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0170-jpapdpstatistics_enginestats.sql
new file mode 100644 (file)
index 0000000..cbd5aa3
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 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 AS a
+SET id = b.id
+FROM pdpstatistics AS b
+WHERE a.name = b.name AND a.version = b.version AND a.timeStamp = b.timeStamp;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0180-jpapdpstatistics_enginestats.sql b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0180-jpapdpstatistics_enginestats.sql
new file mode 100644 (file)
index 0000000..f104113
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 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 jpapdpstatistics_enginestats DROP COLUMN timeStamp;
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0190-jpapolicyaudit.sql b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0190-jpapolicyaudit.sql
new file mode 100644 (file)
index 0000000..319ea00
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 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 jpapolicyaudit (ACTION INT DEFAULT NULL NULL, PDPGROUP VARCHAR(255) NULL, PDPTYPE VARCHAR(255) NULL, TIMESTAMP TIMESTAMP DEFAULT NULL NULL, "USER" VARCHAR(255) NULL, ID BIGINT NOT NULL, name VARCHAR(120) NOT NULL, version VARCHAR(20) NOT NULL, CONSTRAINT PK_JPAPOLICYAUDIT PRIMARY KEY (ID, name, version));
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0200-JpaPolicyAuditIndex_timestamp.sql b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0200-JpaPolicyAuditIndex_timestamp.sql
new file mode 100644 (file)
index 0000000..d789d11
--- /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=========================================================
+ */
+
+CREATE INDEX JpaPolicyAuditIndex_timestamp ON jpapolicyaudit(TIMESTAMP);
diff --git a/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0210-sequence.sql b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0210-sequence.sql
new file mode 100644 (file)
index 0000000..64d6f01
--- /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=========================================================
+ */
+
+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/postgres/0900/upgrade/0220-sequence.sql b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0220-sequence.sql
new file mode 100644 (file)
index 0000000..9c02d14
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 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 COALESCE(max(id),0) FROM pdpstatistics));