argos/dmp-db-scema/updates/01/DMPUser DMPDatasetprofile D...

61 lines
1.4 KiB
SQL

INSERT INTO public."UserDMP"(
usr, dmp, role)
SELECT "Creator", "ID", 0
FROM public."DMP"
DELETE
FROM public."UserDMP" as us1
using public."UserDMP" as us2
where us1."id" < us2."id" AND us1."dmp" = us2."dmp"
CREATE TABLE public."DMPDatasetProfile"
(
"ID" uuid NOT NULL DEFAULT uuid_generate_v4(),
dmp uuid NOT NULL,
datasetprofile uuid NOT NULL,
CONSTRAINT "DMPDatasetProfile_pkey" PRIMARY KEY ("ID"),
CONSTRAINT "DMPDatasetProfile_datasetprofile_fkey" FOREIGN KEY (datasetprofile)
REFERENCES public."DatasetProfile" ("ID") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "DMPDatasetProfile_dmp_fkey" FOREIGN KEY (dmp)
REFERENCES public."DMP" ("ID") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE public."DMPDatasetProfile"
OWNER to dmtadm;
ALTER TABLE public."UserDMP"
OWNER to dmtadm;
INSERT INTO public."DMPDatasetProfile"(
dmp, datasetprofile)
SELECT "ID", unnest(xpath('/profiles/profile/@profileId', dmpp."AssociatedDmps"::xml)::text[]::UUID[])
FROM public."DMP" as dmpp
Alter table public."DMP"
add "FinalizedDat" timestamp(6) with time zone
update public."DMP" SET "FinalizedDat" = "Modified"
where "Status" = 1
Alter table public."Dataset"
add "FinalizedDat" timestamp(6) with time zone
update public."Dataset" SET "FinalizedDat" = "Modified"
where "Status" = 1