diff --git a/kogito-postgres-db-migration-image.yaml b/kogito-postgres-db-migration-image.yaml index c030d873d..107de52fa 100644 --- a/kogito-postgres-db-migration-image.yaml +++ b/kogito-postgres-db-migration-image.yaml @@ -16,7 +16,7 @@ # specific language governing permissions and limitations # under the License. # -name: "docker.io/apache/incubator-kie-kogito-postgres-db-migration" +name: "docker.io/apache/incubator-kie-kogito-service-db-migration-postgresql" version: "999-SNAPSHOT" from: registry.access.redhat.com/ubi8/openjdk-17-runtime:1.19 description: Flyway image for DI/JS database migration diff --git a/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/data-index/V1.32.0__data_index_create.sql b/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/data-index/V1.32.0__data_index_create.sql deleted file mode 100644 index 44634b378..000000000 --- a/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/data-index/V1.32.0__data_index_create.sql +++ /dev/null @@ -1,307 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ -SET SEARCH_PATH="$DATA_INDEX_SCHEMA"; - -create table IF NOT EXISTS attachments -( - id varchar(255) not null, - content varchar(255), - name varchar(255), - updated_at timestamp, - updated_by varchar(255), - task_id varchar(255) not null, - primary key (id) -); - -create table IF NOT EXISTS comments -( - id varchar(255) not null, - content varchar(255), - updated_at timestamp, - updated_by varchar(255), - task_id varchar(255) not null, - primary key (id) -); - -create table IF NOT EXISTS jobs -( - id varchar(255) not null, - callback_endpoint varchar(255), - endpoint varchar(255), - execution_counter int4, - expiration_time timestamp, - last_update timestamp, - node_instance_id varchar(255), - priority int4, - process_id varchar(255), - process_instance_id varchar(255), - repeat_interval int8, - repeat_limit int4, - retries int4, - root_process_id varchar(255), - root_process_instance_id varchar(255), - scheduled_id varchar(255), - status varchar(255), - primary key (id) -); - -create table IF NOT EXISTS milestones -( - id varchar(255) not null, - process_instance_id varchar(255) not null, - name varchar(255), - status varchar(255), - primary key (id, process_instance_id) -); - -create table IF NOT EXISTS nodes -( - id varchar(255) not null, - definition_id varchar(255), - enter timestamp, - exit timestamp, - name varchar(255), - node_id varchar(255), - type varchar(255), - process_instance_id varchar(255) not null, - primary key (id) -); - -create table IF NOT EXISTS processes -( - id varchar(255) not null, - business_key varchar(255), - end_time timestamp, - endpoint varchar(255), - message varchar(255), - node_definition_id varchar(255), - last_update_time timestamp, - parent_process_instance_id varchar(255), - process_id varchar(255), - process_name varchar(255), - root_process_id varchar(255), - root_process_instance_id varchar(255), - start_time timestamp, - state int4, - variables jsonb, - primary key (id) -); - -create table IF NOT EXISTS processes_addons -( - process_id varchar(255) not null, - addon varchar(255) not null, - primary key (process_id, addon) -); - -create table IF NOT EXISTS processes_roles -( - process_id varchar(255) not null, - role varchar(255) not null, - primary key (process_id, role) -); - -create table IF NOT EXISTS tasks -( - id varchar(255) not null, - actual_owner varchar(255), - completed timestamp, - description varchar(255), - endpoint varchar(255), - inputs jsonb, - last_update timestamp, - name varchar(255), - outputs jsonb, - priority varchar(255), - process_id varchar(255), - process_instance_id varchar(255), - reference_name varchar(255), - root_process_id varchar(255), - root_process_instance_id varchar(255), - started timestamp, - state varchar(255), - primary key (id) -); - -create table IF NOT EXISTS tasks_admin_groups -( - task_id varchar(255) not null, - group_id varchar(255) not null, - primary key (task_id, group_id) -); - -create table IF NOT EXISTS tasks_admin_users -( - task_id varchar(255) not null, - user_id varchar(255) not null, - primary key (task_id, user_id) -); - -create table IF NOT EXISTS tasks_excluded_users -( - task_id varchar(255) not null, - user_id varchar(255) not null, - primary key (task_id, user_id) -); - -create table IF NOT EXISTS tasks_potential_groups -( - task_id varchar(255) not null, - group_id varchar(255) not null, - primary key (task_id, group_id) -); - -create table IF NOT EXISTS tasks_potential_users -( - task_id varchar(255) not null, - user_id varchar(255) not null, - primary key (task_id, user_id) -); - -alter table if exists attachments - drop constraint if exists fk_attachments_tasks -cascade; - -alter table if exists attachments - add constraint fk_attachments_tasks - foreign key (task_id) - references tasks - on -delete -cascade; - -alter table if exists comments - drop constraint if exists fk_comments_tasks -cascade; - -alter table if exists comments - add constraint fk_comments_tasks - foreign key (task_id) - references tasks - on -delete -cascade; - -alter table if exists milestones -drop constraint if exists fk_milestones_process -cascade; - -alter table if exists milestones - add constraint fk_milestones_process - foreign key (process_instance_id) - references processes - on -delete -cascade; - -alter table if exists nodes -drop constraint if exists fk_nodes_process -cascade; - -alter table if exists nodes - add constraint fk_nodes_process - foreign key (process_instance_id) - references processes - on -delete -cascade; - -alter table if exists processes_addons -drop constraint if exists fk_processes_addons_processes -cascade; - -alter table if exists processes_addons - add constraint fk_processes_addons_processes - foreign key (process_id) - references processes - on -delete -cascade; - -alter table if exists processes_roles -drop constraint if exists fk_processes_roles_processes -cascade; - -alter table if exists processes_roles - add constraint fk_processes_roles_processes - foreign key (process_id) - references processes - on -delete -cascade; - -alter table if exists tasks_admin_groups -drop constraint if exists fk_tasks_admin_groups_tasks -cascade; - -alter table if exists tasks_admin_groups - add constraint fk_tasks_admin_groups_tasks - foreign key (task_id) - references tasks - on -delete -cascade; - -alter table if exists tasks_admin_users -drop constraint if exists fk_tasks_admin_users_tasks -cascade; - -alter table if exists tasks_admin_users - add constraint fk_tasks_admin_users_tasks - foreign key (task_id) - references tasks - on -delete -cascade; - -alter table if exists tasks_excluded_users -drop constraint if exists fk_tasks_excluded_users_tasks -cascade; - -alter table if exists tasks_excluded_users - add constraint fk_tasks_excluded_users_tasks - foreign key (task_id) - references tasks - on -delete -cascade; - -alter table if exists tasks_potential_groups -drop constraint if exists fk_tasks_potential_groups_tasks -cascade; - -alter table if exists tasks_potential_groups - add constraint fk_tasks_potential_groups_tasks - foreign key (task_id) - references tasks - on -delete -cascade; - -alter table if exists tasks_potential_users -drop constraint if exists fk_tasks_potential_users_tasks -cascade; - -alter table if exists tasks_potential_users - add constraint fk_tasks_potential_users_tasks - foreign key (task_id) - references tasks - on -delete -cascade; diff --git a/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/data-index/V1.44.0__data_index_definitions.sql b/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/data-index/V1.44.0__data_index_definitions.sql deleted file mode 100644 index 3e37b73d7..000000000 --- a/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/data-index/V1.44.0__data_index_definitions.sql +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ - -SET SEARCH_PATH="$DATA_INDEX_SCHEMA"; - -create table IF NOT EXISTS definitions -( - id varchar(255) not null, - version varchar(255) not null, - name varchar(255), - type varchar(255), - source bytea, - endpoint varchar(255), - primary key (id, version) -); - -create table IF NOT EXISTS definitions_addons -( - process_id varchar(255) not null, - process_version varchar(255) not null, - addon varchar(255) not null, - primary key (process_id, process_version, addon) -); - -create table IF NOT EXISTS definitions_roles -( - process_id varchar(255) not null, - process_version varchar(255) not null, - role varchar(255) not null, - primary key (process_id, process_version, role) -); - -alter table if exists definitions_addons -drop constraint if exists fk_definitions_addons_definitions -cascade; - -alter table if exists definitions_addons - add constraint fk_definitions_addons_definitions - foreign key (process_id, process_version) - references definitions - on -delete -cascade; - -alter table if exists definitions_roles -drop constraint if exists fk_definitions_roles_definitions -cascade; - -alter table if exists definitions_roles - add constraint fk_definitions_roles_definitions - foreign key (process_id, process_version) - references definitions - on -delete -cascade; - -alter table if exists processes - add column IF NOT EXISTS version varchar (255); diff --git a/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/data-index/V1.45.0.0__data_index_node_definitions.sql b/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/data-index/V1.45.0.0__data_index_node_definitions.sql deleted file mode 100644 index 26868c09b..000000000 --- a/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/data-index/V1.45.0.0__data_index_node_definitions.sql +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ - -SET SEARCH_PATH="$DATA_INDEX_SCHEMA"; - -create table IF NOT EXISTS definitions_nodes -( - id varchar(255) not null, - name varchar(255), - unique_id varchar(255), - type varchar(255), - process_id varchar(255) not null, - process_version varchar(255) not null, - primary key (id, process_id, process_version) -); - -create table IF NOT EXISTS definitions_nodes_metadata -( - node_id varchar(255) not null, - process_id varchar(255) not null, - process_version varchar(255) not null, - value varchar(255), - key varchar(255) not null, - primary key (node_id, process_id, process_version, key) -); -alter table if exists definitions_nodes -drop constraint if exists fk_definitions_nodes_definitions -cascade; - -alter table if exists definitions_nodes - add constraint fk_definitions_nodes_definitions - foreign key (process_id, process_version) - references definitions - on -delete -cascade; - -alter table if exists definitions_nodes_metadata -drop constraint if exists fk_definitions_nodes_metadata_definitions_nodes -cascade; - -alter table if exists definitions_nodes_metadata - add constraint fk_definitions_nodes_metadata_definitions_nodes - foreign key (node_id, process_id, process_version) - references definitions_nodes - on -delete -cascade; diff --git a/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/data-index/V1.45.0.1__add_identity_to_process_instance.sql b/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/data-index/V1.45.0.1__add_identity_to_process_instance.sql deleted file mode 100644 index 041b2a678..000000000 --- a/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/data-index/V1.45.0.1__add_identity_to_process_instance.sql +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ - -SET SEARCH_PATH="$DATA_INDEX_SCHEMA"; - -ALTER TABLE IF exists processes - ADD COLUMN IF NOT EXISTS created_by character varying, - ADD COLUMN IF NOT EXISTS updated_by character varying; \ No newline at end of file diff --git a/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/data-index/V1.45.0.2__data_index_definitions_add_columns.sql b/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/data-index/V1.45.0.2__data_index_definitions_add_columns.sql deleted file mode 100644 index 151169c4c..000000000 --- a/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/data-index/V1.45.0.2__data_index_definitions_add_columns.sql +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ - -SET SEARCH_PATH="$DATA_INDEX_SCHEMA"; - -create table IF NOT EXISTS definitions_annotations -( - value varchar(255) not null, - process_id varchar(255) not null, - process_version varchar(255) not null, - primary key (value, process_id, process_version) - ); - -create table IF NOT EXISTS definitions_metadata -( - process_id varchar(255) not null, - process_version varchar(255) not null, - value varchar(255), - key varchar(255) not null, - primary key (process_id, process_version, key) - ); - -alter table if exists definitions_annotations -drop constraint if exists fk_definitions_annotations -cascade; - -alter table if exists definitions_annotations - add constraint fk_definitions_annotations - foreign key (process_id, process_version) - references definitions - on -delete -cascade; - -alter table if exists definitions_metadata -drop constraint if exists fk_definitions_metadata -cascade; - -alter table if exists definitions_metadata - add constraint fk_definitions_metadata - foreign key (process_id, process_version) - references definitions - on -delete -cascade; - -alter table if exists definitions - add column IF NOT EXISTS description varchar (255); \ No newline at end of file diff --git a/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/data-index/V1.45.0.3__add_fk_index.sql b/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/data-index/V1.45.0.3__add_fk_index.sql deleted file mode 100644 index 37f99b8ea..000000000 --- a/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/data-index/V1.45.0.3__add_fk_index.sql +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ - -SET SEARCH_PATH="$DATA_INDEX_SCHEMA"; - -create index if not exists idx_attachments_tid on attachments(task_id); -create index if not exists idx_comments_tid on comments(task_id); -create index if not exists idx_definitions_addons_pid_pv on definitions_addons(process_id, process_version); -create index if not exists idx_definitions_annotations_pid_pv on definitions_annotations(process_id, process_version); -create index if not exists idx_definitions_metadata_pid_pv on definitions_metadata(process_id, process_version); -create index if not exists idx_definitions_nodes_pid_pv on definitions_nodes(process_id, process_version); -create index if not exists idx_definitions_nodes_metadata_pid_pv on definitions_nodes_metadata(process_id, process_version); -create index if not exists idx_definitions_roles_pid_pv on definitions_roles(process_id, process_version); -create index if not exists idx_milestones_piid on milestones(process_instance_id); -create index if not exists idx_nodes_piid on nodes(process_instance_id); -create index if not exists idx_processes_addons_pid on processes_addons(process_id); -create index if not exists idx_processes_roles_pid on processes_roles(process_id); -create index if not exists idx_tasks_admin_groups_tid on tasks_admin_groups(task_id); -create index if not exists idx_tasks_admin_users_tid on tasks_admin_users(task_id); -create index if not exists idx_tasks_excluded_users_tid on tasks_excluded_users(task_id); -create index if not exists idx_tasks_potential_groups_tid on tasks_potential_groups(task_id); -create index if not exists idx_tasks_potential_users_tid on tasks_potential_users(task_id); diff --git a/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/data-index/V1.45.0.4__increase_varchar_length.sql b/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/data-index/V1.45.0.4__increase_varchar_length.sql deleted file mode 100644 index b61f7a777..000000000 --- a/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/data-index/V1.45.0.4__increase_varchar_length.sql +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ - -SET SEARCH_PATH="$DATA_INDEX_SCHEMA"; - -alter table if exists processes alter column message type varchar(65535) diff --git a/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/jobs-service/V2.0.0__Create_Table.sql b/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/jobs-service/V2.0.0__Create_Table.sql deleted file mode 100644 index eeb394697..000000000 --- a/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/jobs-service/V2.0.0__Create_Table.sql +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ - -SET SEARCH_PATH="$JOBS_SERVICE_SCHEMA"; - -CREATE TYPE JOB_STATUS AS ENUM -( - 'ERROR', - 'EXECUTED', - 'SCHEDULED', - 'RETRY', - 'CANCELED' -); - -CREATE TYPE JOB_TYPE AS ENUM -( - 'HTTP' -); - -CREATE TABLE job_details -( - id VARCHAR(40) PRIMARY KEY, - correlation_id VARCHAR(40), - status JOB_STATUS, - last_update TIMESTAMPTZ, - retries INT4, - execution_counter INT4, - scheduled_id VARCHAR(40), - payload JSONB, - type JOB_TYPE, - priority INT4, - recipient JSONB, - trigger JSONB -); - -CREATE INDEX status_date ON job_details -( - status, - ((trigger->>'nextFireTime')::INT8) -); \ No newline at end of file diff --git a/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/jobs-service/V2.0.1__job_details_increase_job_id_size.sql b/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/jobs-service/V2.0.1__job_details_increase_job_id_size.sql deleted file mode 100644 index ec03aaa74..000000000 --- a/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/jobs-service/V2.0.1__job_details_increase_job_id_size.sql +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ - -SET SEARCH_PATH="$JOBS_SERVICE_SCHEMA"; - -ALTER TABLE job_details - ALTER COLUMN id TYPE varchar(50); - -ALTER TABLE job_details - ALTER COLUMN correlation_id TYPE varchar(50); \ No newline at end of file diff --git a/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/jobs-service/V2.0.2__job_details_add_fire_time_col.sql b/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/jobs-service/V2.0.2__job_details_add_fire_time_col.sql deleted file mode 100644 index 6ade05adc..000000000 --- a/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/jobs-service/V2.0.2__job_details_add_fire_time_col.sql +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ - -SET SEARCH_PATH="$JOBS_SERVICE_SCHEMA"; - -ALTER TABLE job_details - ADD COLUMN fire_time TIMESTAMPTZ; - -CREATE INDEX job_details_fire_time_idx - ON job_details (fire_time); \ No newline at end of file diff --git a/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/jobs-service/V2.0.3__Create_Table_Management.sql b/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/jobs-service/V2.0.3__Create_Table_Management.sql deleted file mode 100644 index 0a23faf6e..000000000 --- a/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/jobs-service/V2.0.3__Create_Table_Management.sql +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ - -SET SEARCH_PATH="$JOBS_SERVICE_SCHEMA"; - -CREATE TABLE job_service_management -( - id VARCHAR(40) PRIMARY KEY, - last_heartbeat TIMESTAMPTZ, - token VARCHAR(40) UNIQUE -); \ No newline at end of file diff --git a/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/jobs-service/V3.0.0__Create_Jobs_Table_V2.sql b/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/jobs-service/V3.0.0__Create_Jobs_Table_V2.sql deleted file mode 100644 index a48659c77..000000000 --- a/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/jobs-service/V3.0.0__Create_Jobs_Table_V2.sql +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ - -SET SEARCH_PATH="$JOBS_SERVICE_SCHEMA"; - -ALTER TABLE job_details - RENAME TO job_details_v1; - -DROP INDEX job_details_fire_time_idx; -DROP INDEX status_date; - -CREATE TABLE job_details -( - id VARCHAR(50) PRIMARY KEY, - correlation_id VARCHAR(50), - status VARCHAR(40), - last_update TIMESTAMPTZ, - retries INT4, - execution_counter INT4, - scheduled_id VARCHAR(40), - priority INT4, - recipient JSONB, - trigger JSONB, - fire_time TIMESTAMPTZ -); - -CREATE INDEX job_details_fire_time_idx - ON job_details (fire_time); \ No newline at end of file diff --git a/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/jobs-service/V3.0.1__Migrate_Jobs_v1_to_v2_Table.sql b/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/jobs-service/V3.0.1__Migrate_Jobs_v1_to_v2_Table.sql deleted file mode 100644 index 94970e0ef..000000000 --- a/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/jobs-service/V3.0.1__Migrate_Jobs_v1_to_v2_Table.sql +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ - -SET SEARCH_PATH="$JOBS_SERVICE_SCHEMA"; - -INSERT INTO job_details (id, correlation_id, status, last_update, fire_time, retries, execution_counter, scheduled_id, priority, trigger, recipient) - SELECT job.id AS id, - job.correlation_id AS correlation_id, - job.status AS status, - job.last_update AS last_update, - job.fire_time AS fire_time, - job.retries AS retries, - job.execution_counter AS execution_counter, - job.scheduled_id AS scheduled_id, - job.priority AS priority, - job.trigger AS trigger, - json_build_object('url', job.recipient ->> 'endpoint', - 'type', 'http', - 'method', 'POST', - 'classType', 'org.kie.kogito.jobs.service.api.recipient.http.HttpRecipient', - 'queryParams', '{}'::jsonb, - 'headers','{}'::jsonb, - 'payload', null - ) AS recipient - FROM job_details_v1 job WHERE job.id IS NOT NULL; \ No newline at end of file diff --git a/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/jobs-service/V3.0.2__Add_Execution_Timeout_Col.sql b/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/jobs-service/V3.0.2__Add_Execution_Timeout_Col.sql deleted file mode 100644 index 97f2a5a21..000000000 --- a/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/jobs-service/V3.0.2__Add_Execution_Timeout_Col.sql +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ - -SET SEARCH_PATH="$JOBS_SERVICE_SCHEMA"; - -ALTER TABLE job_details - ADD COLUMN execution_timeout BIGINT; - -ALTER TABLE job_details - ADD COLUMN execution_timeout_unit VARCHAR(40); diff --git a/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/jobs-service/V3.0.3__Add_Created_Col.sql b/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/jobs-service/V3.0.3__Add_Created_Col.sql deleted file mode 100644 index 7037cfdcc..000000000 --- a/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/jobs-service/V3.0.3__Add_Created_Col.sql +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ - -SET SEARCH_PATH="$JOBS_SERVICE_SCHEMA"; - -ALTER TABLE job_details - ADD COLUMN created TIMESTAMPTZ; - -UPDATE job_details -SET created = last_update -WHERE created is null; - -CREATE INDEX job_details_created_idx - ON job_details (created); diff --git a/modules/kogito-postgres-db-migration-deps/artifacts/migration.sh b/modules/kogito-postgres-db-migration-deps/artifacts/migration.sh index 111df082d..4a7814ee0 100644 --- a/modules/kogito-postgres-db-migration-deps/artifacts/migration.sh +++ b/modules/kogito-postgres-db-migration-deps/artifacts/migration.sh @@ -18,56 +18,72 @@ # under the License. # -if [ -z "$MIGRATE_DATA_INDEX" ]; then - MIGRATE_DATA_INDEX=true - echo "Migrating data index: $MIGRATE_DATA_INDEX" -fi +# DB migration function +migrate () { + local SERVICE_NAME=$1 # Name of service e.g. data-index or jobs-service + local MIGRATE_DB=$2 # To migrate DB set to true + local DB_URL=$3 + local DB_USER=$4 + local DB_PWD=$5 + local SCHEMA_NAME=$6 -if [ -z "$MIGRATE_JOBS_SERVICE" ]; then - MIGRATE_JOBS_SERVICE=true - echo "Migrating jobs service: $MIGRATE_JOBS_SERVICE" -fi + if $MIGRATE_DB + then + echo USING ENVIRONMENT VARS: $SERVICE_NAME + echo URL=$DB_URL USER=$DB_USER PWD=******** -if $MIGRATE_DATA_INDEX -then - echo DI DB ENV VARS - echo URL=$DI_DB_URL USER=$DI_DB_USER PWD=$DI_DB_PWD + echo LISTING SQL DIR: $SERVICE_NAME + ls /home/default/postgresql/$SERVICE_NAME - if [ -z "$DATA_INDEX_SCHEMA" ]; then - DATA_INDEX_SCHEMA=data-index-service - echo "Using the data index schema: $DATA_INDEX_SCHEMA" + /home/default/flyway/flyway -url="$DB_URL" -user="$DB_USER" -password="$DB_PWD" -mixed="true" -locations="filesystem:/home/default/postgresql/$SERVICE_NAME" -schemas="$SCHEMA_NAME" migrate + /home/default/flyway/flyway -url="$DB_URL" -user="$DB_USER" -password="$DB_PWD" -mixed="true" -locations="filesystem:/home/default/postgresql/$SERVICE_NAME" -schemas="$SCHEMA_NAME" info fi +} - # Update $DATA_INDEX_SCHEMA for data index sql files - cd /home/default/db-migration-files/data-index - for FILE in *; do sed -i.bak 's/$DATA_INDEX_SCHEMA/'$DATA_INDEX_SCHEMA'/' $FILE; done - rm -rf *.bak +# DB migration flag validation +function validateDBMigration() { + local SERVICE_NAME=$1 + local MIGRATE_DB=$2 + echo Validating $SERVICE_NAME for db migration value $MIGRATE_DB + + if [ "${MIGRATE_DB}" = true ] || [ "${MIGRATE_DB}" = false ]; then + echo "DB migration flag for service $SERVICE_NAME will be set to $MIGRATE_DB" + else + echo "DB migration flag for service $SERVICE_NAME, should be either true or false, but found $MIGRATE_DB, exiting" + exit 1 + fi +} - echo LISTING SQL DIR: DATA-INDEX - ls /home/default/db-migration-files/data-index +# Process data-index +SERVICE_DATA_INDEX="data-index" - /home/default/flyway/flyway -url="$DI_DB_URL" -user="$DI_DB_USER" -password="$DI_DB_PWD" -mixed="true" -locations="filesystem:/home/default/db-migration-files/data-index" -schemas="$DATA_INDEX_SCHEMA" migrate - /home/default/flyway/flyway -url="$DI_DB_URL" -user="$DI_DB_USER" -password="$DI_DB_PWD" -mixed="true" -locations="filesystem:/home/default/db-migration-files/data-index" -schemas="$DATA_INDEX_SCHEMA" info +if [ -z "$MIGRATE_DATA_INDEX" ]; then + MIGRATE_DATA_INDEX=true +else + validateDBMigration $SERVICE_DATA_INDEX $MIGRATE_DATA_INDEX fi +echo "Migrating data index: $MIGRATE_DATA_INDEX" -if $MIGRATE_JOBS_SERVICE -then - echo JS DB ENV VARS - echo URL=$JS_DB_URL USER=$JS_DB_USER PWD=$JS_DB_PWD +if [ -z "$DATA_INDEX_SCHEMA" ]; then + DATA_INDEX_SCHEMA=data-index-service + echo "Using the data index schema: $DATA_INDEX_SCHEMA" +fi - if [ -z "$JOBS_SERVICE_SCHEMA" ]; then - JOBS_SERVICE_SCHEMA=jobs-service - echo "Using the jobs service schema: $JOBS_SERVICE_SCHEMA" - fi +migrate $SERVICE_DATA_INDEX $MIGRATE_DATA_INDEX $DI_DB_URL $DI_DB_USER $DI_DB_PWD $DATA_INDEX_SCHEMA - # Update $JOBS_SERVICE_SCHEMA for jobs service sql files - cd /home/default/db-migration-files/jobs-service - for FILE in *; do sed -i.bak 's/$JOBS_SERVICE_SCHEMA/'$JOBS_SERVICE_SCHEMA'/' $FILE; done - rm -rf *.bak +# Process jobs-service +SERVICE_JOBS_SERVICE="jobs-service" - echo LISTING SQL DIR: JOBS-SERVICE - ls /home/default/db-migration-files/jobs-service +if [ -z "$MIGRATE_JOBS_SERVICE" ]; then + MIGRATE_JOBS_SERVICE=true +else + validateDBMigration $SERVICE_JOBS_SERVICE $MIGRATE_JOBS_SERVICE +fi +echo "Migrating jobs service: $MIGRATE_JOBS_SERVICE" - /home/default/flyway/flyway -url="$JS_DB_URL" -user="$JS_DB_USER" -password="$JS_DB_PWD" -mixed="true" -locations="filesystem:/home/default/db-migration-files/jobs-service" -schemas="$JOBS_SERVICE_SCHEMA" migrate - /home/default/flyway/flyway -url="$JS_DB_URL" -user="$JS_DB_USER" -password="$JS_DB_PWD" -mixed="true" -locations="filesystem:/home/default/db-migration-files/jobs-service" -schemas="$JOBS_SERVICE_SCHEMA" info +if [ -z "$JOBS_SERVICE_SCHEMA" ]; then + JOBS_SERVICE_SCHEMA=jobs-service + echo "Using the jobs service schema: $JOBS_SERVICE_SCHEMA" fi + +migrate $SERVICE_JOBS_SERVICE $MIGRATE_JOBS_SERVICE $JS_DB_URL $JS_DB_USER $JS_DB_PWD $JOBS_SERVICE_SCHEMA \ No newline at end of file diff --git a/modules/kogito-postgres-db-migration-deps/install b/modules/kogito-postgres-db-migration-deps/install index a4d0485c7..60b4cca6b 100644 --- a/modules/kogito-postgres-db-migration-deps/install +++ b/modules/kogito-postgres-db-migration-deps/install @@ -21,7 +21,10 @@ mkdir -p /home/default cd /home/default -microdnf install --nodocs tar gzip wget +microdnf install --nodocs tar gzip wget unzip + +wget https://repository.apache.org/content/groups/snapshots/org/kie/kogito/kogito-ddl/10.0.999-SNAPSHOT/kogito-ddl-10.0.999-20240726.011627-10-db-scripts.zip +unzip kogito-ddl-10.0.999-20240726.011627-10-db-scripts.zip wget https://repo1.maven.org/maven2/org/flywaydb/flyway-commandline/10.17.0/flyway-commandline-10.17.0-linux-x64.tar.gz mv flyway-commandline-10.17.0-linux-x64.tar.gz flyway.tar.gz diff --git a/modules/kogito-postgres-db-migration-deps/module.yaml b/modules/kogito-postgres-db-migration-deps/module.yaml index 56309f948..a68fb885f 100644 --- a/modules/kogito-postgres-db-migration-deps/module.yaml +++ b/modules/kogito-postgres-db-migration-deps/module.yaml @@ -20,9 +20,6 @@ schema_version: 1 name: kogito-postgres-db-migration-deps version: "1.0" artifacts: - - name: db-migration-files - path: artifacts/db-migration-files - dest: /home/default/db-migration-files - name: migration.sh path: artifacts/migration.sh dest: /home/default diff --git a/tests/features/kogito-postgres-db-migration-image.feature b/tests/features/kogito-postgres-db-migration-image.feature index 33c3a86e4..4e1f36e10 100644 --- a/tests/features/kogito-postgres-db-migration-image.feature +++ b/tests/features/kogito-postgres-db-migration-image.feature @@ -17,7 +17,7 @@ # under the License. # -@docker.io/apache/incubator-kie-kogito-postgres-db-migration +@docker.io/apache/incubator-kie-kogito-service-db-migration-postgresql Feature: kogito-postgres-db-migration DB migration for postgresql feature. Scenario: verify if all labels are correctly set on kogito-postgres-db-migration-image image