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;
    OWNER to dmptool;

	
ALTER TABLE public."UserDMP"
--    OWNER to dmtadm;
    OWNER to dmptool;
	
	
--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;
