diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 72f7c80fc..705266ea8 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -19,6 +19,7 @@ ## Enhancements +Added Data Index and Jobs Service database migration image for use by a Kubernetes/OpenShift Job, before the Data Index and Jobs Service are deployed. ## Bug Fixes diff --git a/kogito-postgres-db-migration-image.yaml b/kogito-postgres-db-migration-image.yaml new file mode 100644 index 000000000..c030d873d --- /dev/null +++ b/kogito-postgres-db-migration-image.yaml @@ -0,0 +1,45 @@ +# +# 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. +# +name: "docker.io/apache/incubator-kie-kogito-postgres-db-migration" +version: "999-SNAPSHOT" +from: registry.access.redhat.com/ubi8/openjdk-17-runtime:1.19 +description: Flyway image for DI/JS database migration + +labels: + - name: "org.kie.kogito.version" + value: "999-SNAPSHOT" + - name: "maintainer" + value: "Apache KIE " + - name: "io.k8s.description" + value: "Kogito DB Migration creates schemas and tables for Data Index and Jobs Service for PostgreSQL database" + - name: "io.k8s.display-name" + value: "Kogito DB Migration for Data Index and Jobs Service - PostgreSQL" + - name: "io.openshift.tags" + value: "kogito,db-migration" + +modules: + repositories: + - path: modules + install: + - name: kogito-postgres-db-migration-deps + +run: + workdir: "/home/default" + entrypoint: + - "/home/default/migration.sh" \ No newline at end of file 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 new file mode 100644 index 000000000..44634b378 --- /dev/null +++ b/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/data-index/V1.32.0__data_index_create.sql @@ -0,0 +1,307 @@ +/* + * 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 new file mode 100644 index 000000000..3e37b73d7 --- /dev/null +++ b/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/data-index/V1.44.0__data_index_definitions.sql @@ -0,0 +1,74 @@ +/* + * 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 new file mode 100644 index 000000000..26868c09b --- /dev/null +++ b/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/data-index/V1.45.0.0__data_index_node_definitions.sql @@ -0,0 +1,64 @@ +/* + * 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 new file mode 100644 index 000000000..041b2a678 --- /dev/null +++ b/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/data-index/V1.45.0.1__add_identity_to_process_instance.sql @@ -0,0 +1,24 @@ +/* + * 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 new file mode 100644 index 000000000..151169c4c --- /dev/null +++ b/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/data-index/V1.45.0.2__data_index_definitions_add_columns.sql @@ -0,0 +1,64 @@ +/* + * 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 new file mode 100644 index 000000000..37f99b8ea --- /dev/null +++ b/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/data-index/V1.45.0.3__add_fk_index.sql @@ -0,0 +1,38 @@ +/* + * 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 new file mode 100644 index 000000000..b61f7a777 --- /dev/null +++ b/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/data-index/V1.45.0.4__increase_varchar_length.sql @@ -0,0 +1,22 @@ +/* + * 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 new file mode 100644 index 000000000..eeb394697 --- /dev/null +++ b/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/jobs-service/V2.0.0__Create_Table.sql @@ -0,0 +1,56 @@ +/* + * 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 new file mode 100644 index 000000000..ec03aaa74 --- /dev/null +++ b/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/jobs-service/V2.0.1__job_details_increase_job_id_size.sql @@ -0,0 +1,26 @@ +/* + * 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 new file mode 100644 index 000000000..6ade05adc --- /dev/null +++ b/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/jobs-service/V2.0.2__job_details_add_fire_time_col.sql @@ -0,0 +1,26 @@ +/* + * 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 new file mode 100644 index 000000000..0a23faf6e --- /dev/null +++ b/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/jobs-service/V2.0.3__Create_Table_Management.sql @@ -0,0 +1,27 @@ +/* + * 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 new file mode 100644 index 000000000..a48659c77 --- /dev/null +++ b/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/jobs-service/V3.0.0__Create_Jobs_Table_V2.sql @@ -0,0 +1,44 @@ +/* + * 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 new file mode 100644 index 000000000..94970e0ef --- /dev/null +++ b/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/jobs-service/V3.0.1__Migrate_Jobs_v1_to_v2_Table.sql @@ -0,0 +1,41 @@ +/* + * 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 new file mode 100644 index 000000000..97f2a5a21 --- /dev/null +++ b/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/jobs-service/V3.0.2__Add_Execution_Timeout_Col.sql @@ -0,0 +1,26 @@ +/* + * 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 new file mode 100644 index 000000000..7037cfdcc --- /dev/null +++ b/modules/kogito-postgres-db-migration-deps/artifacts/db-migration-files/jobs-service/V3.0.3__Add_Created_Col.sql @@ -0,0 +1,30 @@ +/* + * 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 new file mode 100644 index 000000000..111df082d --- /dev/null +++ b/modules/kogito-postgres-db-migration-deps/artifacts/migration.sh @@ -0,0 +1,73 @@ +#!/bin/bash +# +# 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. +# + +if [ -z "$MIGRATE_DATA_INDEX" ]; then + MIGRATE_DATA_INDEX=true + echo "Migrating data index: $MIGRATE_DATA_INDEX" +fi + +if [ -z "$MIGRATE_JOBS_SERVICE" ]; then + MIGRATE_JOBS_SERVICE=true + echo "Migrating jobs service: $MIGRATE_JOBS_SERVICE" +fi + +if $MIGRATE_DATA_INDEX +then + echo DI DB ENV VARS + echo URL=$DI_DB_URL USER=$DI_DB_USER PWD=$DI_DB_PWD + + if [ -z "$DATA_INDEX_SCHEMA" ]; then + DATA_INDEX_SCHEMA=data-index-service + echo "Using the data index schema: $DATA_INDEX_SCHEMA" + 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 + + echo LISTING SQL DIR: DATA-INDEX + ls /home/default/db-migration-files/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 +fi + +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 "$JOBS_SERVICE_SCHEMA" ]; then + JOBS_SERVICE_SCHEMA=jobs-service + echo "Using the jobs service schema: $JOBS_SERVICE_SCHEMA" + fi + + # 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 + + echo LISTING SQL DIR: JOBS-SERVICE + ls /home/default/db-migration-files/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 +fi diff --git a/modules/kogito-postgres-db-migration-deps/install b/modules/kogito-postgres-db-migration-deps/install new file mode 100644 index 000000000..a4d0485c7 --- /dev/null +++ b/modules/kogito-postgres-db-migration-deps/install @@ -0,0 +1,42 @@ +#!/bin/sh +# +# 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. +# + +mkdir -p /home/default +cd /home/default + +microdnf install --nodocs tar gzip wget + +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 + +tar -xf /home/default/flyway.tar.gz +mv flyway-10.17.0 flyway + +chmod a+x migration.sh + +chgrp -R 0 /home/default +chown -R 0 /home/default +chmod -R g=u /home/default + +ls -al /home/default +ls -al /home/default/flyway +ls -al /home/default/db-migration-files + +microdnf clean all \ No newline at end of file diff --git a/modules/kogito-postgres-db-migration-deps/module.yaml b/modules/kogito-postgres-db-migration-deps/module.yaml new file mode 100644 index 000000000..56309f948 --- /dev/null +++ b/modules/kogito-postgres-db-migration-deps/module.yaml @@ -0,0 +1,30 @@ +# +# 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. +# +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 +execute: + - script: install diff --git a/scripts/build-kogito-apps-components.sh b/scripts/build-kogito-apps-components.sh index 564506e41..91c6816f7 100755 --- a/scripts/build-kogito-apps-components.sh +++ b/scripts/build-kogito-apps-components.sh @@ -51,6 +51,9 @@ if [ ! -z "${CYPRESS_BINARY_URL}" ]; then fi case ${imageName} in + "kogito-postgres-db-migration") + contextDir="" + ;; "kogito-data-index-ephemeral") contextDir="data-index/data-index-service/data-index-service-inmemory" ;; diff --git a/tests/features/kogito-postgres-db-migration-image.feature b/tests/features/kogito-postgres-db-migration-image.feature new file mode 100644 index 000000000..33c3a86e4 --- /dev/null +++ b/tests/features/kogito-postgres-db-migration-image.feature @@ -0,0 +1,34 @@ +# +# 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. +# + +@docker.io/apache/incubator-kie-kogito-postgres-db-migration +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 + Given image is built + Then the image should contain label maintainer with value Apache KIE + And the image should contain label io.k8s.description with value Kogito DB Migration creates schemas and tables for Data Index and Jobs Service for PostgreSQL database + And the image should contain label io.k8s.display-name with value Kogito DB Migration for Data Index and Jobs Service - PostgreSQL + And the image should contain label io.openshift.tags with value kogito,db-migration + + Scenario: Verify log entries + When container is started with command bash -c '/home/default/migration.sh' + Then container log should contain LISTING SQL DIR + And container log should contain V1.44.0__data_index_definitions.sql + And container log should contain V2.0.1__job_details_increase_job_id_size.sql \ No newline at end of file