From 6a8c5ac947c96656500f942515b7a034cfd90691 Mon Sep 17 00:00:00 2001 From: "CITE\\amentis" Date: Wed, 2 Oct 2024 13:36:49 +0300 Subject: [PATCH] add sql scripts --- .../00.01.072_Add_PlanStatus_table.sql | 1 + .../00.01.073_Add_DescriptionStatus_table.sql | 1 + ..._Insert_values_Workflows_Tenant_config.sql | 23 ++++++++ ...Migrate_Plan_Description_status_column.sql | 58 +++++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 dmp-db-scema/updates/00.01.076_Insert_values_Workflows_Tenant_config.sql create mode 100644 dmp-db-scema/updates/00.01.077_Migrate_Plan_Description_status_column.sql diff --git a/dmp-db-scema/updates/00.01.072_Add_PlanStatus_table.sql b/dmp-db-scema/updates/00.01.072_Add_PlanStatus_table.sql index 9d58b53d8..927640eb9 100644 --- a/dmp-db-scema/updates/00.01.072_Add_PlanStatus_table.sql +++ b/dmp-db-scema/updates/00.01.072_Add_PlanStatus_table.sql @@ -15,6 +15,7 @@ BEGIN internal_status smallint, tenant uuid, definition xml, + action character varying(250) COLLATE pg_catalog."default", CONSTRAINT "PlanStatus_pkey" PRIMARY KEY (id), CONSTRAINT "PlanStatus_tenant_fkey" FOREIGN KEY (tenant) REFERENCES public."Tenant" (id) MATCH SIMPLE diff --git a/dmp-db-scema/updates/00.01.073_Add_DescriptionStatus_table.sql b/dmp-db-scema/updates/00.01.073_Add_DescriptionStatus_table.sql index cd329d07e..d5568fe99 100644 --- a/dmp-db-scema/updates/00.01.073_Add_DescriptionStatus_table.sql +++ b/dmp-db-scema/updates/00.01.073_Add_DescriptionStatus_table.sql @@ -15,6 +15,7 @@ BEGIN internal_status smallint, definition xml, tenant uuid, + action character varying(250) COLLATE pg_catalog."default", CONSTRAINT "DescriptionStatus_pkey" PRIMARY KEY (id), CONSTRAINT "DescriptionStatus_tenant_fkey" FOREIGN KEY (tenant) REFERENCES public."Tenant" (id) MATCH SIMPLE diff --git a/dmp-db-scema/updates/00.01.076_Insert_values_Workflows_Tenant_config.sql b/dmp-db-scema/updates/00.01.076_Insert_values_Workflows_Tenant_config.sql new file mode 100644 index 000000000..f0759c5eb --- /dev/null +++ b/dmp-db-scema/updates/00.01.076_Insert_values_Workflows_Tenant_config.sql @@ -0,0 +1,23 @@ +DO $$DECLARE + this_version CONSTANT varchar := '00.01.076'; +BEGIN + PERFORM * FROM "DBVersion" WHERE version = this_version; + IF FOUND THEN RETURN; END IF; + + INSERT INTO public."PlanStatus" (id, name, description, created_at, updated_at, is_active, internal_status, tenant, definition, action) VALUES ('cb3ced76-9807-4829-82da-75777de1bc78', 'Draft', NULL, '2024-09-17 07:37:24.288404', '2024-09-20 10:34:51.23021', 1, 0, NULL, 'OwnerViewerDescriptionContributorReviewerfalsefalseExport', NULL); + INSERT INTO public."PlanStatus" (id, name, description, created_at, updated_at, is_active, internal_status, tenant, definition, action) VALUES ('f1a3da63-0bff-438f-8b46-1a81ca176115', 'Finalized', NULL, '2024-09-16 14:16:56.685177', '2024-09-23 12:58:56.093437', 1, 1, NULL, 'OwnerfalsefalseDepositExport', 'Finalize'); + INSERT INTO public."PlanStatus" (id, name, description, created_at, updated_at, is_active, internal_status, tenant, definition, action) VALUES ('61fd91f5-c63a-45bc-aa7a-e1f00fbd8545', 'Validated', NULL, '2024-09-17 07:36:38.386887', '2024-09-23 12:28:31.57448', 1, NULL, NULL, 'ReviewerfalsefalseExport', 'Validate'); + INSERT INTO public."PlanStatus" (id, name, description, created_at, updated_at, is_active, internal_status, tenant, definition, action) VALUES ('313cce74-f44b-4a72-9cd8-a9c75fe03a7e', 'Under Review', NULL, '2024-09-17 07:36:58.677058', '2024-09-23 12:28:48.897145', 1, NULL, NULL, 'OwnerfalsefalseExport', 'Review'); + + INSERT INTO public."DescriptionStatus" (id, name, description, created_at, updated_at, is_active, internal_status, definition, tenant, action) VALUES ('978e6ff6-b5e9-4cee-86cb-bc7401ec4059', 'Draft', NULL, '2024-09-16 12:46:20.459486', '2024-09-20 12:21:00.641011', 1, 0, 'OwnerViewerDescriptionContributorReviewerfalsefalseExport', NULL, NULL); + INSERT INTO public."DescriptionStatus" (id, name, description, created_at, updated_at, is_active, internal_status, definition, tenant, action) VALUES ('60f5e529-7ed3-4be1-8754-ac8c7443f246', 'Canceled', NULL, '2024-09-17 15:37:42.256424', '2024-09-25 07:47:24.839357', 1, 2, 'OwnerfalsefalseExport', NULL, 'Cancel'); + INSERT INTO public."DescriptionStatus" (id, name, description, created_at, updated_at, is_active, internal_status, definition, tenant, action) VALUES ('c266e2ee-9ae9-4a2f-9b4b-bc6fb1dd54aa', 'Finalized', NULL, '2024-09-17 07:38:15.846399', '2024-09-23 12:55:39.702483', 1, 1, 'OwnerfalsefalseExport', NULL, 'Finalize'); + + INSERT INTO public."PlanWorkflow" (id, name, description, created_at, updated_at, is_active, definition, tenant) VALUES ('44df0e24-7879-48cc-bbe0-cd8a2b618855', 'default', NULL, '2024-09-18 11:39:30.5974', '2024-09-18 11:39:30.611945', 1, 'cb3ced76-9807-4829-82da-75777de1bc78cb3ced76-9807-4829-82da-75777de1bc78313cce74-f44b-4a72-9cd8-a9c75fe03a7e313cce74-f44b-4a72-9cd8-a9c75fe03a7e61fd91f5-c63a-45bc-aa7a-e1f00fbd854561fd91f5-c63a-45bc-aa7a-e1f00fbd8545f1a3da63-0bff-438f-8b46-1a81ca176115f1a3da63-0bff-438f-8b46-1a81ca176115cfa5cff0-0cbf-4ae7-87b7-263343991f35cb3ced76-9807-4829-82da-75777de1bc78f1a3da63-0bff-438f-8b46-1a81ca176115f1a3da63-0bff-438f-8b46-1a81ca176115cb3ced76-9807-4829-82da-75777de1bc78', NULL); + INSERT INTO public."DescriptionWorkflow" (id, name, description, created_at, updated_at, is_active, definition, tenant) VALUES ('8651af83-8b24-4776-ae45-329031db9f5e', 'default', NULL, '2024-09-17 07:39:00.221933', '2024-09-18 10:51:14.478419', 1, '978e6ff6-b5e9-4cee-86cb-bc7401ec4059978e6ff6-b5e9-4cee-86cb-bc7401ec4059c266e2ee-9ae9-4a2f-9b4b-bc6fb1dd54aac266e2ee-9ae9-4a2f-9b4b-bc6fb1dd54aa978e6ff6-b5e9-4cee-86cb-bc7401ec4059', NULL); + + + INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.076', '2024-09-18 12:00:00.000000+02', now(), 'Insert values for Plan, Description Status and Workflow.'); + + +END$$; \ No newline at end of file diff --git a/dmp-db-scema/updates/00.01.077_Migrate_Plan_Description_status_column.sql b/dmp-db-scema/updates/00.01.077_Migrate_Plan_Description_status_column.sql new file mode 100644 index 000000000..c9a72c9c0 --- /dev/null +++ b/dmp-db-scema/updates/00.01.077_Migrate_Plan_Description_status_column.sql @@ -0,0 +1,58 @@ +DO $$DECLARE + this_version CONSTANT varchar := '00.01.077'; +BEGIN + PERFORM * FROM "DBVersion" WHERE version = this_version; + IF FOUND THEN RETURN; END IF; + + ALTER TABLE public."Plan" + ADD COLUMN status_id uuid; + ALTER TABLE public."Plan" + ADD CONSTRAINT "Plan_status_fkey" FOREIGN KEY (status_id) + REFERENCES public."PlanStatus" (id) + ON UPDATE NO ACTION + ON DELETE NO ACTION + NOT VALID; + + UPDATE public."Plan" SET + status_id = 'cb3ced76-9807-4829-82da-75777de1bc78' + WHERE status = 0; + + UPDATE public."Plan" SET + status_id = 'f1a3da63-0bff-438f-8b46-1a81ca176115' + WHERE status = 1; + + ALTER TABLE IF EXISTS public."Plan" DROP COLUMN IF EXISTS status; + ALTER TABLE public."Plan" ALTER COLUMN status_id SET NOT NULL; + ALTER TABLE IF EXISTS public."Plan" RENAME status_id TO status; + + + + ALTER TABLE public."Description" + ADD COLUMN status_id uuid; + ALTER TABLE public."Description" + ADD CONSTRAINT "Description_status_fkey" FOREIGN KEY (status_id) + REFERENCES public."DescriptionStatus" (id) + ON UPDATE NO ACTION + ON DELETE NO ACTION + NOT VALID; + + UPDATE public."Description" SET + status_id = '978e6ff6-b5e9-4cee-86cb-bc7401ec4059' + WHERE status = 0; + + UPDATE public."Description" SET + status_id = 'c266e2ee-9ae9-4a2f-9b4b-bc6fb1dd54aa' + WHERE status = 1; + + UPDATE public."Description" SET + status_id = '60f5e529-7ed3-4be1-8754-ac8c7443f246' + WHERE status = 2; + + ALTER TABLE IF EXISTS public."Description" DROP COLUMN IF EXISTS status; + ALTER TABLE public."Description" ALTER COLUMN status_id SET NOT NULL; + ALTER TABLE IF EXISTS public."Description" RENAME status_id TO status; + + + INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.077', '2024-07-29 12:00:00.000000+02', now(), 'Migrate status collumns.'); + +END$$; \ No newline at end of file