fix sql scripts

This commit is contained in:
Efstratios Giannopoulos 2023-11-22 13:31:00 +02:00
parent 62a5a6fe1d
commit 6f2d4f016d
12 changed files with 75 additions and 49 deletions

View File

@ -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.');

View File

@ -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.');

View File

@ -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.');

View File

@ -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.');

View File

@ -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).');

View File

@ -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.');

View File

@ -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;

View File

@ -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."UserDescriptionTemplate" RENAME usr TO "user";
ALTER TABLE public."UserDatasetProfile" RENAME TO "UserDescriptionTemplate";
ALTER TABLE public."UserDescriptionTemplate" RENAME "descriptionTemplate" TO description_template;
ALTER TABLE public."UserDescriptionTemplate" RENAME usr TO "user";
ALTER TABLE public."UserDescriptionTemplate" ALTER COLUMN "role" TYPE smallint;
ALTER TABLE public."UserDescriptionTemplate" ALTER COLUMN "role" SET NOT NULL;
ALTER TABLE public."UserDescriptionTemplate" RENAME "descriptionTemplate" TO description_template;
ALTER TABLE public."UserDescriptionTemplate" ADD COLUMN updated_at timestamp without time zone;
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 created_at timestamp without time zone;
ALTER TABLE public."UserDescriptionTemplate" ADD COLUMN updated_at timestamp without time zone;
ALTER TABLE public."UserDescriptionTemplate" ADD COLUMN is_active smallint;
ALTER TABLE public."UserDescriptionTemplate" ADD COLUMN created_at timestamp without time zone;
UPDATE public."UserDescriptionTemplate" SET is_active = 1;
ALTER TABLE public."UserDescriptionTemplate" ADD COLUMN is_active smallint;
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 = 1;
ALTER TABLE public."UserDescriptionTemplate" ALTER COLUMN is_active SET NOT NULL;
UPDATE public."UserDescriptionTemplate" SET is_active = 0 where role = 2;
UPDATE public."UserDescriptionTemplate" SET role = 1 where is_active = 0;
UPDATE public."UserDescriptionTemplate" SET updated_at = now() at time zone 'utc';
ALTER TABLE public."UserDescriptionTemplate" ALTER COLUMN is_active SET NOT NULL;
ALTER TABLE public."UserDescriptionTemplate" ALTER COLUMN updated_at SET NOT NULL;
UPDATE public."UserDescriptionTemplate" SET updated_at = now() at time zone 'utc';
UPDATE public."UserDescriptionTemplate" SET created_at = now() at time zone 'utc';
ALTER TABLE public."UserDescriptionTemplate" ALTER COLUMN updated_at SET NOT NULL;
ALTER TABLE public."UserDescriptionTemplate" ALTER COLUMN created_at SET NOT NULL;
UPDATE public."UserDescriptionTemplate" SET created_at = now() at time zone 'utc';
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$$;

View File

@ -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).');

View File

@ -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).');

View File

@ -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

View File

@ -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;