summaryrefslogtreecommitdiffstats
path: root/policy-db-migrator/src/main
diff options
context:
space:
mode:
authorwaynedunican <wayne.dunican@est.tech>2022-01-11 09:20:28 +0000
committerWayne Dunican <wayne.dunican@est.tech>2022-01-20 08:35:21 +0000
commitd6057690cc4849bc47f16f3dadd3ec9dcbe3e58d (patch)
treec9c88c1e20a2538b923686ea382f586b80364140 /policy-db-migrator/src/main
parent794b0c933f409a8cdba8216072103a2abf7207fe (diff)
Add upgrade/downgrade scripts for postgres in db-migrator
- Istanbul upgrade scripts - Istanbul downgrade scripts Issue-ID: POLICY-2715 Change-Id: I0dcfd11acaf5971581db081f2ff18b7657d0c7af Signed-off-by: Wayne Dunican <wayne.dunican@est.tech>
Diffstat (limited to 'policy-db-migrator/src/main')
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0100-pdp.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0110-idx_tsidx1.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0120-pk_pdpstatistics.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0130-pdpstatistics.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0140-pk_pdpstatistics.sql22
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0150-pdpstatistics.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0160-jpapdpstatistics_enginestats.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0170-jpapdpstatistics_enginestats.sql22
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0180-jpapdpstatistics_enginestats.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0190-jpapolicyaudit.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0200-JpaPolicyAuditIndex_timestamp.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0210-sequence.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0220-sequence.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0100-pdp.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0110-idx_tsidx1.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0120-pk_pdpstatistics.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0130-pdpstatistics.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0140-pk_pdpstatistics.sql22
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0150-pdpstatistics.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0160-jpapdpstatistics_enginestats.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0170-jpapdpstatistics_enginestats.sql22
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0180-jpapdpstatistics_enginestats.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0190-jpapolicyaudit.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0200-JpaPolicyAuditIndex_timestamp.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0210-sequence.sql20
-rw-r--r--policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0220-sequence.sql20
26 files changed, 528 insertions, 0 deletions
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
index 00000000..fbc9c47d
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0100-pdp.sql
@@ -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
index 00000000..4df00a1b
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0110-idx_tsidx1.sql
@@ -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
index 00000000..65425348
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0120-pk_pdpstatistics.sql
@@ -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
index 00000000..a8d021ff
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0130-pdpstatistics.sql
@@ -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
index 00000000..6b87eef3
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0140-pk_pdpstatistics.sql
@@ -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
index 00000000..17c4e6a8
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0150-pdpstatistics.sql
@@ -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
index 00000000..b2bdb432
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0160-jpapdpstatistics_enginestats.sql
@@ -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
index 00000000..8a33f691
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0170-jpapdpstatistics_enginestats.sql
@@ -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
index 00000000..114467bf
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0180-jpapdpstatistics_enginestats.sql
@@ -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
index 00000000..3a6176f4
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0190-jpapolicyaudit.sql
@@ -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
index 00000000..284ca0c1
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0200-JpaPolicyAuditIndex_timestamp.sql
@@ -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
index 00000000..43043485
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0210-sequence.sql
@@ -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
index 00000000..f2724415
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/downgrade/0220-sequence.sql
@@ -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
index 00000000..7c923d3e
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0100-pdp.sql
@@ -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
index 00000000..0becab72
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0110-idx_tsidx1.sql
@@ -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
index 00000000..c6d8d8ed
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0120-pk_pdpstatistics.sql
@@ -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
index 00000000..611a7b9b
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0130-pdpstatistics.sql
@@ -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
index 00000000..86fe9779
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0140-pk_pdpstatistics.sql
@@ -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
index 00000000..5cf66cf2
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0150-pdpstatistics.sql
@@ -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
index 00000000..9ca423fd
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0160-jpapdpstatistics_enginestats.sql
@@ -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
index 00000000..cbd5aa30
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0170-jpapdpstatistics_enginestats.sql
@@ -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
index 00000000..f1041131
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0180-jpapdpstatistics_enginestats.sql
@@ -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
index 00000000..319ea004
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0190-jpapolicyaudit.sql
@@ -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
index 00000000..d789d118
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0200-JpaPolicyAuditIndex_timestamp.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 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
index 00000000..64d6f01b
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0210-sequence.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 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
index 00000000..9c02d144
--- /dev/null
+++ b/policy-db-migrator/src/main/docker/config/policyadmin/postgres/0900/upgrade/0220-sequence.sql
@@ -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));