Merge branch 'dmp-refactoring' of https://code-repo.d4science.org/MaDgiK-CITE/argos into dmp-refactoring

This commit is contained in:
Thomas Georgios Giannos 2023-11-21 10:00:25 +02:00
commit 99bf7d29f9
6 changed files with 309 additions and 0 deletions

View File

@ -0,0 +1,23 @@
DO $$DECLARE
this_version CONSTANT varchar := '00.01.017';
BEGIN
PERFORM * FROM "DBVersion" WHERE version = this_version;
IF FOUND THEN RETURN; END IF;
CREATE TABLE public."User"
(
id uuid NOT NULL,
name character varying(250),
additional_info character varying,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
is_active smallint NOT NULL,
PRIMARY KEY (id)
)
WITH (
OIDS = FALSE
);
INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.017', '2023-11-20 12:00:00.000000+02', now(), 'Add table User.');
END$$;

View File

@ -0,0 +1,26 @@
DO $$DECLARE
this_version CONSTANT varchar := '00.01.018';
BEGIN
PERFORM * FROM "DBVersion" WHERE version = this_version;
IF FOUND THEN RETURN; END IF;
CREATE TABLE public."UserCredential"
(
id uuid NOT NULL,
"user" uuid NOT NULL,
external_id character varying(512) NOT NULL,
created_at timestamp without time zone NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY ("user")
REFERENCES public."User" (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID
)
WITH (
OIDS = FALSE
);
INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.018', '2023-11-20 12:00:00.000000+02', now(), 'Add table UserCredential.');
END$$;

View File

@ -0,0 +1,28 @@
DO $$DECLARE
this_version CONSTANT varchar := '00.01.019';
BEGIN
PERFORM * FROM "DBVersion" WHERE version = this_version;
IF FOUND THEN RETURN; END IF;
CREATE TABLE public."UserContactInfo"
(
id uuid NOT NULL,
"user" uuid NOT NULL,
ordinal integer NOT NULL DEFAULT 0,
type smallint NOT NULL,
value character varying(512) NOT NULL,
created_at timestamp without time zone NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY ("user")
REFERENCES public."User" (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID
)
WITH (
OIDS = FALSE
);
INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.019', '2023-11-20 12:00:00.000000+02', now(), 'Add table UserContactInfo.');
END$$;

View File

@ -0,0 +1,33 @@
DO $$DECLARE
this_version CONSTANT varchar := '00.01.020';
BEGIN
PERFORM * FROM "DBVersion" WHERE version = this_version;
IF FOUND THEN RETURN; END IF;
TRUNCATE public."UserRole";
ALTER TABLE public."UserRole" DROP COLUMN "Role";
ALTER TABLE public."UserRole"
RENAME "Id" TO id;
ALTER TABLE public."UserRole"
RENAME "UserId" TO "user";
ALTER TABLE public."UserRole"
ADD COLUMN role character varying(512) NOT NULL;
ALTER TABLE public."UserRole"
ADD COLUMN created_at timestamp without time zone NOT NULL;
ALTER TABLE public."UserRole" DROP CONSTRAINT "UserRole_userId_fkey";
ALTER TABLE public."UserRole"
ADD FOREIGN KEY ("user")
REFERENCES public."User" (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.020', '2023-11-20 12:00:00.000000+02', now(), 'Sync table UserRole.');
END$$;

View File

@ -0,0 +1,28 @@
DO $$DECLARE
this_version CONSTANT varchar := '00.01.021';
BEGIN
PERFORM * FROM "DBVersion" WHERE version = this_version;
IF FOUND THEN RETURN; END IF;
INSERT INTO public."User" ("id", "name", "created_at","updated_at", "is_active")
SELECT "id", "name", "created", "lastloggedin", CASE
WHEN userstatus = 1
THEN 0
ELSE 1
END
FROM public."UserInfo";
INSERT INTO public."UserContactInfo" ("id", "user", "created_at","ordinal", "type", "value")
SELECT uuid_generate_v1(), "id", "created", 0, 0, "email"
FROM public."UserInfo"
WHERE "email" is not null AND email != '';
INSERT INTO public."UserContactInfo" ("id", "user", "created_at", "ordinal", "type", "value")
SELECT uuid_generate_v1(), "UserId", "CreationTime", 1, 0, "Email"
FROM public."Credential"
WHERE "Email" is not null AND "Email" != '';
INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.021', '2023-11-20 12:00:00.000000+02', now(), 'Sync user tables data.');
END$$;

View File

@ -0,0 +1,171 @@
DO $$DECLARE
this_version CONSTANT varchar := '00.01.022';
BEGIN
PERFORM * FROM "DBVersion" WHERE version = this_version;
IF FOUND THEN RETURN; END IF;
ALTER TABLE public."Credential" DROP CONSTRAINT fkey_credential_user;
ALTER TABLE public."Credential"
ADD FOREIGN KEY ("UserId")
REFERENCES public."User" (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."DMP" DROP CONSTRAINT fk_dmp_creator;
ALTER TABLE public."DMP"
ADD FOREIGN KEY ("Creator")
REFERENCES public."User" (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."Dataset" DROP CONSTRAINT fk_dataset_creator;
ALTER TABLE public."Dataset"
ADD FOREIGN KEY ("Creator")
REFERENCES public."User" (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."Description" DROP CONSTRAINT "Description_created_by_fkey";
ALTER TABLE public."Description"
ADD FOREIGN KEY (created_by)
REFERENCES public."User" (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."Dmp" DROP CONSTRAINT "Dmp_creator_fkey";
ALTER TABLE public."Dmp"
ADD FOREIGN KEY (creator)
REFERENCES public."User" (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."DmpUser" DROP CONSTRAINT "DmpUser_user_fkey";
ALTER TABLE public."DmpUser"
ADD FOREIGN KEY ("user")
REFERENCES public."User" (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."FileUpload" DROP CONSTRAINT fk_fileupload_creator;
ALTER TABLE public."FileUpload"
ADD FOREIGN KEY ("Creator")
REFERENCES public."User" (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."Grant" DROP CONSTRAINT fk_grant_creator;
ALTER TABLE public."Grant"
ADD FOREIGN KEY ("CreationUser")
REFERENCES public."User" (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."Invitation" DROP CONSTRAINT fk_invitation_creator;
ALTER TABLE public."Invitation"
ADD FOREIGN KEY ("CreationUser")
REFERENCES public."User" (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."Lock" DROP CONSTRAINT "LockUserReference";
ALTER TABLE public."Lock"
ADD FOREIGN KEY ("LockedBy")
REFERENCES public."User" (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."Notification" DROP CONSTRAINT "NotificationUserReference";
ALTER TABLE public."Notification"
ADD FOREIGN KEY ("UserId")
REFERENCES public."User" (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."Project" DROP CONSTRAINT fk_project_creator;
ALTER TABLE public."Project"
ADD FOREIGN KEY ("CreationUser")
REFERENCES public."User" (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."Reference" DROP CONSTRAINT "Reference_created_by_fkey";
ALTER TABLE public."Reference"
ADD FOREIGN KEY (created_by)
REFERENCES public."User" (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."Tag" DROP CONSTRAINT "Tag_created_by_fkey";
ALTER TABLE public."Tag"
ADD FOREIGN KEY (created_by)
REFERENCES public."User" (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."UserDMP" DROP CONSTRAINT "UserDMP_usr_fkey";
ALTER TABLE public."UserDMP"
ADD FOREIGN KEY (usr)
REFERENCES public."User" (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."UserDescriptionTemplate" DROP CONSTRAINT "UserDatasetProfile_usr_fkey";
ALTER TABLE public."UserDescriptionTemplate"
ADD FOREIGN KEY ("user")
REFERENCES public."User" (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
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."UserToken" DROP CONSTRAINT fkey_usetoken_user;
ALTER TABLE public."UserToken"
ADD FOREIGN KEY ("UserId")
REFERENCES public."User" (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.022', '2023-11-20 12:00:00.000000+02', now(), 'Update user tables fks.');
END$$;