From 6f2d4f016d26adca87b192fd7c0e1b0391fc84f7 Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Wed, 22 Nov 2023 13:31:00 +0200 Subject: [PATCH] fix sql scripts --- .../00.01.002_Align_Entity_Doi_table.sql | 2 +- .../00.01.003_Add_UserSettings_table.sql | 2 +- .../updates/00.01.005_Add_Dmp_table.sql | 50 ++++++++++++------- .../00.01.006_Add_Dmp_reference_table.sql | 2 +- ...7_Add_Description_table_former_Dataset.sql | 2 +- ....01.008_Add_DescriptionReference_table.sql | 2 +- ...01.010_Align_DescriptionTemplate_table.sql | 2 + ...11_Align_UserDescriptionTemplate_table.sql | 42 ++++++++++------ ...012_Add_Dmp_description_template_table.sql | 2 +- .../updates/00.01.013_Add_Dmp_User_table.sql | 2 +- dmp-db-scema/updates/00.01.015_addTag.sql | 2 +- .../updates/00.01.022_updateUserFKs.sql | 14 +++--- 12 files changed, 75 insertions(+), 49 deletions(-) diff --git a/dmp-db-scema/updates/00.01.002_Align_Entity_Doi_table.sql b/dmp-db-scema/updates/00.01.002_Align_Entity_Doi_table.sql index b591c6648..dddc01fa7 100644 --- a/dmp-db-scema/updates/00.01.002_Align_Entity_Doi_table.sql +++ b/dmp-db-scema/updates/00.01.002_Align_Entity_Doi_table.sql @@ -26,7 +26,7 @@ ALTER TABLE public."EntityDoi" RENAME "EntityId" TO entity_id; ALTER TABLE public."EntityDoi" - ADD COLUMN is_active smallint NOT NULL DEFAULT 1 + ADD COLUMN is_active smallint NOT NULL DEFAULT 1; INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.002', '2023-10-19 12:00:00.000000+02', now(), 'Align Entity Doi table.'); diff --git a/dmp-db-scema/updates/00.01.003_Add_UserSettings_table.sql b/dmp-db-scema/updates/00.01.003_Add_UserSettings_table.sql index 055ee67a3..e6a6fe054 100644 --- a/dmp-db-scema/updates/00.01.003_Add_UserSettings_table.sql +++ b/dmp-db-scema/updates/00.01.003_Add_UserSettings_table.sql @@ -15,7 +15,7 @@ CREATE TABLE IF NOT EXISTS public.UserSettings value text COLLATE pg_catalog."default" NOT NULL, name character varying(500) COLLATE pg_catalog."default" NOT NULL, CONSTRAINT user_settings_pkey PRIMARY KEY (id) -) +); INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.003', '2023-10-19 12:00:00.000000+02', now(), 'Add UserSettings table.'); diff --git a/dmp-db-scema/updates/00.01.005_Add_Dmp_table.sql b/dmp-db-scema/updates/00.01.005_Add_Dmp_table.sql index 3ce623126..04e2e7c1a 100644 --- a/dmp-db-scema/updates/00.01.005_Add_Dmp_table.sql +++ b/dmp-db-scema/updates/00.01.005_Add_Dmp_table.sql @@ -4,27 +4,41 @@ BEGIN PERFORM * FROM "DBVersion" WHERE version = this_version; IF FOUND THEN RETURN; END IF; -CREATE TABLE IF NOT EXISTS public."Dmp" +CREATE TABLE public."Dmp" ( - "id" uuid NOT NULL, - "label" character varying(250) COLLATE pg_catalog."default" NOT NULL, - "version" integer NOT NULL, - "status" smallint NOT NULL DEFAULT 0, - "properties" text COLLATE pg_catalog."default", - "dmp_properties" text COLLATE pg_catalog."default", - "group_id" uuid, - "description" text COLLATE pg_catalog."default", - "is_public" boolean NOT NULL DEFAULT false, - "extra_properties" text COLLATE pg_catalog."default", - "created_at" timestamp without time zone NOT NULL DEFAULT now(), - "updated_at" timestamp without time zone NOT NULL DEFAULT now(), - "is_active" smallint NOT NULL DEFAULT 1, - "version_status" smallint NOT NULL DEFAULT 1, - "finalized_at" timestamp without time zone, - "published_at" timestamp without time zone, + id uuid NOT NULL, + label character varying(250) COLLATE pg_catalog."default" NOT NULL, + version integer NOT NULL, + status smallint NOT NULL DEFAULT 0, + properties text COLLATE pg_catalog."default", + group_id uuid NOT NULL, + description text COLLATE pg_catalog."default", + created_at timestamp without time zone NOT NULL DEFAULT now(), + updated_at timestamp without time zone NOT NULL DEFAULT now(), + is_active smallint NOT NULL DEFAULT 1, + finalized_at timestamp without time zone, + creator uuid NOT NULL, + blueprint uuid NOT NULL, + language character varying(100) COLLATE pg_catalog."default" NOT NULL, + access_type smallint NOT NULL, + public_after timestamp without time zone, + version_status smallint NOT NULL DEFAULT 1, CONSTRAINT "Dmp_pkey" PRIMARY KEY (id), - CONSTRAINT "Dmp_creator_fkey" FOREIGN KEY (creator) REFERENCES public."UserInfo" (id) + CONSTRAINT "Dmp_blueprint_fkey" FOREIGN KEY (blueprint) + REFERENCES public."DmpBlueprint" (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION + NOT VALID, + CONSTRAINT "Dmp_creator_fkey" FOREIGN KEY (creator) + REFERENCES public."UserInfo" (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION + NOT VALID ) +WITH ( + OIDS = FALSE +) +TABLESPACE pg_default; INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.005', '2023-10-27 12:00:00.000000+02', now(), 'Add Dmp table.'); diff --git a/dmp-db-scema/updates/00.01.006_Add_Dmp_reference_table.sql b/dmp-db-scema/updates/00.01.006_Add_Dmp_reference_table.sql index 81b9dd635..232672afd 100644 --- a/dmp-db-scema/updates/00.01.006_Add_Dmp_reference_table.sql +++ b/dmp-db-scema/updates/00.01.006_Add_Dmp_reference_table.sql @@ -16,7 +16,7 @@ CREATE TABLE IF NOT EXISTS public."DmpReference" CONSTRAINT "DmpReference_pkey" PRIMARY KEY (id), CONSTRAINT "DmpReference_dmp_id_fkey" FOREIGN KEY ("dmp_id") REFERENCES public."Dmp"("id"), CONSTRAINT "DmpReference_reference_id_fkey" FOREIGN KEY ("reference_id") REFERENCES public."Reference"("id") -) +); INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.006', '2023-10-27 12:00:00.000000+02', now(), 'Add DescriptionReference table.'); diff --git a/dmp-db-scema/updates/00.01.007_Add_Description_table_former_Dataset.sql b/dmp-db-scema/updates/00.01.007_Add_Description_table_former_Dataset.sql index efd2ef90d..324730c60 100644 --- a/dmp-db-scema/updates/00.01.007_Add_Description_table_former_Dataset.sql +++ b/dmp-db-scema/updates/00.01.007_Add_Description_table_former_Dataset.sql @@ -23,7 +23,7 @@ CREATE TABLE IF NOT EXISTS public."Description" CONSTRAINT "Description_pkey" PRIMARY KEY (id), CONSTRAINT "Description_dmp_fkey" FOREIGN KEY ("dmp") REFERENCES public."Dmp"("id"), CONSTRAINT "Description_profile_fkey" FOREIGN KEY ("profile") REFERENCES public."DescriptionTemplate"("ID") -) +); INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.007', '2023-10-27 12:00:00.000000+02', now(), 'Add Description table (former Dataset).'); diff --git a/dmp-db-scema/updates/00.01.008_Add_DescriptionReference_table.sql b/dmp-db-scema/updates/00.01.008_Add_DescriptionReference_table.sql index e9c9aaa5d..0fd7b879f 100644 --- a/dmp-db-scema/updates/00.01.008_Add_DescriptionReference_table.sql +++ b/dmp-db-scema/updates/00.01.008_Add_DescriptionReference_table.sql @@ -16,7 +16,7 @@ CREATE TABLE IF NOT EXISTS public."DescriptionReference" CONSTRAINT "DescriptionReference_pkey" PRIMARY KEY (id), CONSTRAINT "DescriptionReference_description_fkey" FOREIGN KEY ("description_id") REFERENCES public."Description"("id"), CONSTRAINT "DescriptionReference_reference_fkey" FOREIGN KEY ("reference_id") REFERENCES public."Reference"("id") -) +); INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.008', '2023-10-27 12:00:00.000000+02', now(), 'Add DescriptionReference table.'); diff --git a/dmp-db-scema/updates/00.01.010_Align_DescriptionTemplate_table.sql b/dmp-db-scema/updates/00.01.010_Align_DescriptionTemplate_table.sql index fa45e8cac..c90c23c39 100644 --- a/dmp-db-scema/updates/00.01.010_Align_DescriptionTemplate_table.sql +++ b/dmp-db-scema/updates/00.01.010_Align_DescriptionTemplate_table.sql @@ -24,6 +24,8 @@ ALTER TABLE public."DescriptionTemplate" ALTER COLUMN created_at TYPE timestamp ALTER TABLE public."DescriptionTemplate" ALTER COLUMN updated_at TYPE timestamp without time zone ; +ALTER TABLE public."DescriptionTemplate" ALTER COLUMN group_id DROP DEFAULT; + ALTER TABLE public."DescriptionTemplate" ADD COLUMN is_active smallint; UPDATE public."DescriptionTemplate" SET is_active = 1; diff --git a/dmp-db-scema/updates/00.01.011_Align_UserDescriptionTemplate_table.sql b/dmp-db-scema/updates/00.01.011_Align_UserDescriptionTemplate_table.sql index 7735e159c..5506d56d2 100644 --- a/dmp-db-scema/updates/00.01.011_Align_UserDescriptionTemplate_table.sql +++ b/dmp-db-scema/updates/00.01.011_Align_UserDescriptionTemplate_table.sql @@ -1,29 +1,39 @@ -ALTER TABLE public."UserDatasetProfile" RENAME TO "UserDescriptionTemplate"; +DO $$DECLARE + this_version CONSTANT varchar := '00.01.011'; +BEGIN + PERFORM * FROM "DBVersion" WHERE version = this_version; + IF FOUND THEN RETURN; END IF; + + ALTER TABLE public."UserDatasetProfile" RENAME TO "UserDescriptionTemplate"; -ALTER TABLE public."UserDescriptionTemplate" RENAME usr TO "user"; + ALTER TABLE public."UserDescriptionTemplate" RENAME usr TO "user"; -ALTER TABLE public."UserDescriptionTemplate" RENAME "descriptionTemplate" TO description_template; + ALTER TABLE public."UserDescriptionTemplate" RENAME "descriptionTemplate" TO description_template; -ALTER TABLE public."UserDescriptionTemplate" ALTER COLUMN "role" TYPE smallint; -ALTER TABLE public."UserDescriptionTemplate" ALTER COLUMN "role" SET NOT NULL; + ALTER TABLE public."UserDescriptionTemplate" ALTER COLUMN "role" TYPE smallint; + ALTER TABLE public."UserDescriptionTemplate" ALTER COLUMN "role" SET NOT NULL; -ALTER TABLE public."UserDescriptionTemplate" ADD COLUMN updated_at timestamp without time zone; + ALTER TABLE public."UserDescriptionTemplate" ADD COLUMN updated_at timestamp without time zone; -ALTER TABLE public."UserDescriptionTemplate" ADD COLUMN created_at timestamp without time zone; + ALTER TABLE public."UserDescriptionTemplate" ADD COLUMN created_at timestamp without time zone; -ALTER TABLE public."UserDescriptionTemplate" ADD COLUMN is_active smallint; + ALTER TABLE public."UserDescriptionTemplate" ADD COLUMN is_active smallint; -UPDATE public."UserDescriptionTemplate" SET is_active = 1; + UPDATE public."UserDescriptionTemplate" SET is_active = 1; -UPDATE public."UserDescriptionTemplate" SET is_active = 0 where role = 2; -UPDATE public."UserDescriptionTemplate" SET role = 1 where is_active = 0; + UPDATE public."UserDescriptionTemplate" SET is_active = 0 where role = 2; + UPDATE public."UserDescriptionTemplate" SET role = 1 where is_active = 0; -ALTER TABLE public."UserDescriptionTemplate" ALTER COLUMN is_active SET NOT NULL; + ALTER TABLE public."UserDescriptionTemplate" ALTER COLUMN is_active SET NOT NULL; -UPDATE public."UserDescriptionTemplate" SET updated_at = now() at time zone 'utc'; + UPDATE public."UserDescriptionTemplate" SET updated_at = now() at time zone 'utc'; -ALTER TABLE public."UserDescriptionTemplate" ALTER COLUMN updated_at SET NOT NULL; + ALTER TABLE public."UserDescriptionTemplate" ALTER COLUMN updated_at SET NOT NULL; -UPDATE public."UserDescriptionTemplate" SET created_at = now() at time zone 'utc'; + UPDATE public."UserDescriptionTemplate" SET created_at = now() at time zone 'utc'; -ALTER TABLE public."UserDescriptionTemplate" ALTER COLUMN created_at SET NOT NULL; \ No newline at end of file + ALTER TABLE public."UserDescriptionTemplate" ALTER COLUMN created_at SET NOT NULL; + + INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.011', '2023-11-02 12:00:00.000000+02', now(), 'Aling UserDescriptionTemplate table (former UserDatasetProfile).'); + +END$$; \ No newline at end of file diff --git a/dmp-db-scema/updates/00.01.012_Add_Dmp_description_template_table.sql b/dmp-db-scema/updates/00.01.012_Add_Dmp_description_template_table.sql index 21ff5a190..0bb8f804b 100644 --- a/dmp-db-scema/updates/00.01.012_Add_Dmp_description_template_table.sql +++ b/dmp-db-scema/updates/00.01.012_Add_Dmp_description_template_table.sql @@ -18,7 +18,7 @@ CREATE TABLE IF NOT EXISTS public."DmpDescriptionTemplate" REFERENCES public."Dmp" (id), CONSTRAINT "DmpDescriptionTemplate_description_template_fkey" FOREIGN KEY (description_template) REFERENCES public."DescriptionTemplate" (id) -) +); INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.012', '2023-11-02 12:00:00.000000+02', now(), 'Add Dmp Description Template table (former DMPDatasetProfile).'); diff --git a/dmp-db-scema/updates/00.01.013_Add_Dmp_User_table.sql b/dmp-db-scema/updates/00.01.013_Add_Dmp_User_table.sql index be1f00b64..fc1fe0004 100644 --- a/dmp-db-scema/updates/00.01.013_Add_Dmp_User_table.sql +++ b/dmp-db-scema/updates/00.01.013_Add_Dmp_User_table.sql @@ -18,7 +18,7 @@ CREATE TABLE IF NOT EXISTS public."DmpUser" REFERENCES public."Dmp" (id), CONSTRAINT "DmpUser_user_fkey" FOREIGN KEY ("user") REFERENCES public."UserInfo" (id) -) +); INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.013', '2023-11-07 12:00:00.000000+02', now(), 'Add Dmp User table (former UserDMP).'); diff --git a/dmp-db-scema/updates/00.01.015_addTag.sql b/dmp-db-scema/updates/00.01.015_addTag.sql index 59aeeaa3f..b6d43c70c 100644 --- a/dmp-db-scema/updates/00.01.015_addTag.sql +++ b/dmp-db-scema/updates/00.01.015_addTag.sql @@ -14,7 +14,7 @@ BEGIN updated_at timestamp without time zone NOT NULL, CONSTRAINT "Tag_pkey" PRIMARY KEY (id), CONSTRAINT "Tag_created_by_fkey" FOREIGN KEY (created_by) - REFERENCES public."User" (id) MATCH SIMPLE + REFERENCES public."UserInfo" (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION NOT VALID diff --git a/dmp-db-scema/updates/00.01.022_updateUserFKs.sql b/dmp-db-scema/updates/00.01.022_updateUserFKs.sql index fc5626644..f463e80e9 100644 --- a/dmp-db-scema/updates/00.01.022_updateUserFKs.sql +++ b/dmp-db-scema/updates/00.01.022_updateUserFKs.sql @@ -148,14 +148,14 @@ BEGIN ON DELETE NO ACTION NOT VALID; - ALTER TABLE public."UserPreference" DROP CONSTRAINT userpreference_user_fk; +-- ALTER TABLE public."UserPreference" DROP CONSTRAINT userpreference_user_fk; - ALTER TABLE public."UserPreference" - ADD FOREIGN KEY ("UserId") - REFERENCES public."User" (id) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION - NOT VALID; +-- ALTER TABLE public."UserPreference" +-- ADD FOREIGN KEY ("UserId") +-- REFERENCES public."User" (id) MATCH SIMPLE +-- ON UPDATE NO ACTION +-- ON DELETE NO ACTION +-- NOT VALID; ALTER TABLE public."UserToken" DROP CONSTRAINT fkey_usetoken_user;