Commit 9651be1b authored by George Kalampokis's avatar George Kalampokis

Removed old database updates (redundant)

parent c003c646
......@@ -14,4 +14,4 @@ INSERT INTO public."DoiFunder"(name, doi) VALUES ('National Science Foundation',
INSERT INTO public."DoiFunder"(name, doi) VALUES ('Nederlandse Organisatie voor Wetenschappelijk Onderzoek', '10.13039/501100003246');
INSERT INTO public."DoiFunder"(name, doi) VALUES ('Wellcome Trust', '10.13039/100004440');
INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.00.002', '2020-05-06 18:11:00.000000+03', now(), 'Add Doi Funder');
\ No newline at end of file
INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.00.003', '2020-05-06 18:11:00.000000+03', now(), 'Add Doi Funder');
\ No newline at end of file
......@@ -20,5 +20,7 @@ INSERT INTO public."DoiFunder"(name, doi) VALUES ('National Science Foundation',
INSERT INTO public."DoiFunder"(name, doi) VALUES ('Nederlandse Organisatie voor Wetenschappelijk Onderzoek', '10.13039/501100003246');
INSERT INTO public."DoiFunder"(name, doi) VALUES ('Wellcome Trust', '10.13039/100004440');
INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.00.003', '2020-05-06 18:11:00.000000+03', now(), 'Add Doi Funder');
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 :POSTGRES_USER;
ALTER TABLE public."UserDMP"
-- OWNER to dmtadm;
OWNER to :POSTGRES_USER;
--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;
alter table public."DMP"
Add "isPublic" boolean NOT NULL Default False;
UPDATE public."DMP"
SET "isPublic" = True
WHERE "Status" = 1;
\ No newline at end of file
ALTER TABLE public."Dataset"
RENAME COLUMN "FinalizedDat" TO "FinalizedAt";
\ No newline at end of file
ALTER TABLE public."DMP"
ADD "PublishedAt" timestamp(6) WITH time zone;
UPDATE public."DMP"
SET "PublishedAt" = "FinalizedDat"
where "isPublic" = True;
\ No newline at end of file
ALTER TABLE public."DMP"
RENAME COLUMN "FinalizedDat" TO "FinalizedAt";
\ No newline at end of file
ALTER TABLE public."DMP"
ADD COLUMN "DOI" text;
\ No newline at end of file
CREATE TABLE public."Content" (
"Id" uuid NOT NULL,
"Filename" character varying NOT NULL,
"Extension" character varying NOT NULL,
"ParentType" numeric NOT NULL,
"Uri" character varying NOT NULL,
"LocationType" numeric NOT NULL
);
ALTER TABLE public."Content" OWNER TO :POSTGRES_USER;
ALTER TABLE ONLY public."Content"
ADD CONSTRAINT "Content_pkey" PRIMARY KEY ("Id");
CREATE TABLE public."LoginConfirmationEmail"
(
"ID" uuid NOT NULL,
email character varying COLLATE pg_catalog."default" NOT NULL,
"isConfirmed" boolean NOT NULL,
token uuid NOT NULL,
userId uuid NOT NULL,
"expiresAt" timestamp(4) with time zone NOT NULL,
CONSTRAINT "LoginConfirmationEmail_pkey" PRIMARY KEY ("ID")
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE public."LoginConfirmationEmail"
-- OWNER to dmtadm;
OWNER to :POSTGRES_USER;
\ No newline at end of file
ALTER TABLE public."UserInfo"
ALTER COLUMN "email"
DROP NOT NULL
\ No newline at end of file
UPDATE public."DatasetProfile"
SET "Description" = ''
\ No newline at end of file
ALTER TABLE public."DatasetProfile"
ALTER COLUMN "Description"
SET NOT NULL
\ No newline at end of file
ALTER TABLE "Project"
RENAME TO "Grant";
\ No newline at end of file
CREATE TABLE public."Funder"
(
"ID" uuid NOT NULL DEFAULT uuid_generate_v4(),
"Label" character varying(250) COLLATE pg_catalog."default" NOT NULL,
"Reference" character varying COLLATE pg_catalog."default",
"Definition" character varying COLLATE pg_catalog."default",
"Status" smallint NOT NULL DEFAULT 0,
"Created" timestamp(4) with time zone NOT NULL DEFAULT now(),
"Modified" timestamp(4) with time zone NOT NULL DEFAULT now(),
"Type" numeric NOT NULL DEFAULT 0,
CONSTRAINT "Funder_pkey" PRIMARY KEY ("ID")
)
\ No newline at end of file
ALTER TABLE "Grant"
ADD COLUMN "Funder" uuid
\ No newline at end of file
ALTER TABLE public."Grant"
ADD COLUMN "Content" uuid;
ALTER TABLE public."Grant"
ADD CONSTRAINT fk_grant_content FOREIGN KEY ("Content")
REFERENCES public."Content" ("Id") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION;
\ No newline at end of file
ALTER TABLE public."Grant"
RENAME CONSTRAINT "fk_project_creator" TO "fk_grant_creator";
\ No newline at end of file
ALTER TABLE public."Grant"
RENAME CONSTRAINT "Project_pkey" TO "Grant_pkey";
\ No newline at end of file
ALTER TABLE public."DMP"
RENAME COLUMN "Project" to "Grant"
\ No newline at end of file
CREATE TABLE public."Project"
(
"ID" uuid NOT NULL DEFAULT uuid_generate_v4(),
"Label" character varying(250) COLLATE pg_catalog."default" NOT NULL,
"Abbreviation" character varying(50) COLLATE pg_catalog."default",
"Reference" character varying COLLATE pg_catalog."default",
"Uri" character varying(250) COLLATE pg_catalog."default",
"Definition" character varying COLLATE pg_catalog."default",
"Status" smallint NOT NULL DEFAULT 0,
"Created" timestamp(4) with time zone NOT NULL DEFAULT now(),
"Modified" timestamp(4) with time zone NOT NULL DEFAULT now(),
"StartDate" timestamp(4) with time zone,
"EndDate" timestamp(4) with time zone,
"Description" text COLLATE pg_catalog."default",
"CreationUser" uuid,
"Type" numeric NOT NULL DEFAULT 0,
"Content" uuid,
CONSTRAINT "Project_pkey" PRIMARY KEY ("ID"),
CONSTRAINT fk_project_content FOREIGN KEY ("Content")
REFERENCES public."Content" ("Id") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT fk_project_creator FOREIGN KEY ("CreationUser")
REFERENCES public."UserInfo" (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
\ No newline at end of file
ALTER TABLE public."DMP"
ADD COLUMN "Project" uuid
\ No newline at end of file
ALTER TABLE public."Grant"
ALTER COLUMN "Reference" TYPE character varying(255);
ALTER TABLE public."Grant"
ALTER COLUMN "Definition" TYPE character varying;
ALTER TABLE public."Registry"
ALTER COLUMN "Reference" TYPE character varying;
ALTER TABLE public."Service"
ALTER COLUMN "Reference" TYPE character varying;
ALTER TABLE public."Researcher"
ALTER COLUMN "Reference" TYPE character varying;
ALTER TABLE public."DataRepository"
ALTER COLUMN "Reference" TYPE character varying;
ALTER TABLE "Funder"
ADD COLUMN "CreationUser" uuid;
\ No newline at end of file
Update "Funder" as funder
set "CreationUser" = grant1."CreationUser"
from "Grant" as grant1
where funder."ID" = grant1."Funder" ;
\ No newline at end of file
CREATE TABLE public."ExternalDataset" (
"Id" uuid DEFAULT public.uuid_generate_v4() NOT NULL,
"Label" character varying NOT NULL,
"Abbreviation" character varying,
"Reference" character varying NOT NULL,
"Created" timestamp(4) with time zone NOT NULL,
"Modified" timestamp(4) with time zone NOT NULL
);
ALTER TABLE public."ExternalDataset" OWNER TO :POSTGRES_USER;
ALTER TABLE ONLY public."ExternalDataset"
ADD CONSTRAINT "ExternalDataset_pkey" PRIMARY KEY ("Id");
ALTER TABLE "DataRepository"
ADD COLUMN "CreationUser" uuid;
ALTER TABLE "ExternalDataset"
ADD COLUMN "CreationUser" uuid;
ALTER TABLE "Registry"
ADD COLUMN "CreationUser" uuid;
ALTER TABLE "Service"
ADD COLUMN "CreationUser" uuid;
\ No newline at end of file
ALTER TABLE "Researcher"
ADD COLUMN "CreationUser" uuid;
\ No newline at end of file
-- Registry Update Script
UPDATE public."Registry"
SET "Reference" = REPLACE("Reference", 'dmpdata/', 'dmp:')
WHERE "Reference" LIKE 'dmpdata/%';
-- Service Update Script
UPDATE public."Service"
SET "Reference" = REPLACE("Reference", 'dmpdata/', 'dmp:')
WHERE "Reference" LIKE 'dmpdata/%';
UPDATE public."Service"
SET "Reference" = REPLACE("Reference", 'innerdata/', 'dmp:')
WHERE "Reference" LIKE 'innerdata/%';
-- DataRepository
UPDATE public."DataRepository"
SET "Reference" = REPLACE("Reference", 'dmpdata/', 'dmp:')
where "Reference" like 'dmpdata/%';
UPDATE public."DataRepository"
SET "Reference" = CONCAT('re3data:', "Reference")
where "Reference" LIKE '%:re3data%';
UPDATE public."DataRepository"
SET "Reference" = CONCAT('dmp:', "Reference")
where "Reference" LIKE '%:internal%';
UPDATE public."DataRepository"
SET "Reference" = CONCAT('eestore:', "Reference")
where "Reference" LIKE '%:eestore%';
-- ExternalDataset
UPDATE public."ExternalDataset"
SET "Reference" = REPLACE("Reference", 'dmpdata/', 'dmp:')
WHERE "Reference" LIKE 'dmpdata/%';
\ No newline at end of file
-- Grant
UPDATE public."Grant"
SET "Reference" = CONCAT('cristin:', "Reference")
WHERE "Reference" LIKE '%cristin/%';
UPDATE public."Grant"
SET "Reference" = CONCAT('OpenAIRE:', "Reference")
where "Reference" like '%_________::%' and
"Reference" not like 'OpenAIRE:%';
-- Funder
UPDATE public."Funder"
SET "Reference" = CONCAT('cristin:', "Reference")
WHERE "Reference" LIKE '%cristin/%';
UPDATE public."Funder"
SET "Reference" = CONCAT('openaire:', "Reference")
WHERE "Reference" LIKE '%_________::%' and
upper("Reference") NOT LIKE upper('openAIRE:%');
-- Project
UPDATE public."Project"
SET "Reference" = CONCAT('cristin:', "Reference")
WHERE "Reference" LIKE '%cristin/%';
UPDATE public."Project"
SET "Reference" = CONCAT('openaire:', "Reference")
WHERE "Reference" LIKE '%_________::%' and
upper("Reference") NOT LIKE upper('openAIRE:%');
\ No newline at end of file
UPDATE "Dataset" AS dataset
SET "Status" = 2
WHERE dataset."ID" in (
SELECT dataset1."ID"
FROM "Dataset" AS dataset1
INNER JOIN "DMP" AS dmp ON dmp."ID" = dataset1."DMP"
WHERE dmp."isPublic" = true AND dataset1."Status" = 0
)
\ No newline at end of file
UPDATE "Funder"
SET "Reference" = CONCAT('dmp:', "ID")
WHERE "Reference" LIKE 'dmp:%';
UPDATE "Grant"
SET "Reference" = CONCAT('dmp:', "ID")
WHERE "Reference" LIKE 'dmp:%';
UPDATE "Project"
SET "Reference" = CONCAT('dmp:', "ID")
WHERE "Reference" LIKE 'dmp:%';
\ No newline at end of file
UPDATE "Researcher"
SET "Reference" = CONCAT('dmp:', "ID")
WHERE "ID" IN (
SELECT "ID" FROM "Researcher"
WHERE "Reference" LIKE 'dmp:%'
)
\ No newline at end of file
CREATE TABLE public."Lock" (
id uuid NOT NULL,
"Target" uuid NOT NULL,
"LockedBy" uuid NOT NULL,
"LockedAt" timestamp NOT NULL,
"TouchedAt" timestamp
);
ALTER TABLE ONLY public."Lock"
ADD CONSTRAINT "Lock_pkey" PRIMARY KEY (id);
ALTER TABLE ONLY public."Lock"
ADD CONSTRAINT "LockUserReference" FOREIGN KEY ("LockedBy") REFERENCES public."UserInfo"(id);
CREATE TABLE public."Notification" (
id uuid NOT NULL,
"UserId" uuid,
"IsActive" integer NOT NULL,
"Type" integer NOT NULL,
"ContactTypeHint" integer,
"ContactHint" character varying,
"Data" character varying,
"NotifyState" integer NOT NULL,
"NotifiedAt" timestamp without time zone,
"RetryCount" integer,
"CreatedAt" timestamp without time zone,
"UpdatedAt" timestamp without time zone
);
ALTER TABLE ONLY public."Notification"
ADD CONSTRAINT "Notification_pkey" PRIMARY KEY (id);
ALTER TABLE ONLY public."Notification"
ADD CONSTRAINT "NotificationUserReference" FOREIGN KEY ("UserId") REFERENCES public."UserInfo"(id);
CREATE TABLE public."DBVersion" (
key character varying NOT NULL,
version character varying NOT NULL,
"releasedAt" timestamp with time zone NOT NULL,
"deployedAt" timestamp with time zone,
description text
);
INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.00.001', '2020-03-31 11:34:54.236152+03', now(), 'Add Database Versioning');
ALTER TABLE public."DMP"
ADD COLUMN "DmpProperties" text;
ALTER TABLE public."DMP"
ADD COLUMN "GroupId" uuid;
ALTER TABLE public."DMP"
ADD COLUMN "Properties" text;
ALTER TABLE public."DatasetProfile"
ADD COLUMN "GroupId" uuid;
ALTER TABLE public."DatasetProfile"
ADD COLUMN "Version" integer;
ALTER TABLE public."Grant"
ADD COLUMN "Type" numeric NOT NULL;
ALTER TABLE public."DatasetDataRepository"
ADD COLUMN "Data" character varying;
ALTER TABLE public."DatasetService"
ADD COLUMN "Data" character varying;
\ No newline at end of file
CREATE TABLE public."Credential" (
"Id" uuid NOT NULL,
"Status" numeric NOT NULL,
"Provider" numeric NOT NULL,
"Public" character varying NOT NULL,
"Secret" character varying NOT NULL,
"CreationTime" timestamp(4) with time zone NOT NULL,
"LastUpdateTime" timestamp(4) with time zone NOT NULL,
"UserId" uuid NOT NULL,
"ExternalId" character varying NOT NULL
);
ALTER TABLE public."Credential" OWNER TO :POSTGRES_USER;
ALTER TABLE ONLY public."Credential"
ADD CONSTRAINT "Credential_pkey" PRIMARY KEY ("Id");
ALTER TABLE ONLY public."Credential"
ADD CONSTRAINT fkey_credential_user FOREIGN KEY ("UserId") REFERENCES public."UserInfo"(id);
INSERT INTO public."UserInfo"(email, authorization_level, usertype, name, created, additionalinfo) VALUES ('fake@email.org', 1, 1, :'ADMIN_USERNAME', now(), '{}');
INSERT INTO public."Credential" VALUES (uuid_generate_v4(), 0, 5, :'ADMIN_USERNAME', :'ADMIN_PASSWORD', now(), now(), (SELECT public."UserInfo"."id" FROM public."UserInfo" WHERE name = :'ADMIN_USERNAME'), 'dmp');
CREATE TABLE public."UserToken" (
"Token" uuid NOT NULL,
"UserId" uuid NOT NULL,
"IssuedAt" timestamp(4) with time zone NOT NULL,
"ExpiresAt" timestamp(4) with time zone NOT NULL
);
ALTER TABLE public."UserToken" OWNER TO :POSTGRES_USER;
ALTER TABLE ONLY public."UserToken"
ADD CONSTRAINT "UserToken_pkey" PRIMARY KEY ("Token");
ALTER TABLE ONLY public."UserToken"
ADD CONSTRAINT fkey_usetoken_user FOREIGN KEY ("UserId") REFERENCES public."UserInfo"(id);
CREATE TABLE public."UserRole" (
"Id" uuid DEFAULT public.uuid_generate_v4() NOT NULL,
"Role" numeric DEFAULT 0 NOT NULL,
"UserId" uuid NOT NULL
);
ALTER TABLE public."UserRole" OWNER TO :POSTGRES_USER;
ALTER TABLE ONLY public."UserRole"
ADD CONSTRAINT "UserRole_pkey" PRIMARY KEY ("Id");
ALTER TABLE ONLY public."UserRole"
ADD CONSTRAINT "UserRole_userId_fkey" FOREIGN KEY ("UserId") REFERENCES public."UserInfo"(id);
INSERT INTO public."UserRole"("Role", "UserId") VALUES (2, (SELECT public."UserInfo"."id" FROM public."UserInfo" WHERE name = 'admin'));
DROP TABLE IF EXISTS "UserAuth" CASCADE;
\ No newline at end of file
AlTER TABLE "DMP"
ALTER COLUMN "Creator" DROP NOT NULL;
\ No newline at end of file
CREATE TABLE public."DatasetExternalDataset" (
"Id" uuid DEFAULT public.uuid_generate_v4() NOT NULL,
"Dataset" uuid NOT NULL,
"ExternalDataset" uuid NOT NULL,
"Role" numeric,
"Data" character varying
);
ALTER TABLE public."DatasetExternalDataset" OWNER TO :POSTGRES_USER;
ALTER TABLE ONLY public."DatasetExternalDataset"
ADD CONSTRAINT "DatasetExternalDataset_pkey" PRIMARY KEY ("Id");
ALTER TABLE ONLY public."DatasetExternalDataset"
ADD CONSTRAINT fkey_datasetexternaldataset_dataset FOREIGN KEY ("Dataset") REFERENCES public."Dataset"("ID");
ALTER TABLE ONLY public."DatasetExternalDataset"
ADD CONSTRAINT fkey_datasetexternaldataset_externaldataset FOREIGN KEY ("ExternalDataset") REFERENCES public."ExternalDataset"("Id");
CREATE TABLE public."Invitation" (
"Id" uuid NOT NULL,
"InvitationEmail" character varying NOT NULL,
"Token" uuid NOT NULL,
"CreationUser" uuid NOT NULL,
"Dmp" uuid NOT NULL,
"Properties" xml,
"AcceptedInvitation" boolean
);
ALTER TABLE public."Invitation" OWNER TO :POSTGRES_USER;
ALTER TABLE ONLY public."Invitation"
ADD CONSTRAINT "Invitation_pkey" PRIMARY KEY ("Id");
ALTER TABLE ONLY public."Invitation"
ADD CONSTRAINT fk_invitation_creator FOREIGN KEY ("CreationUser") REFERENCES public."UserInfo"(id);
ALTER TABLE ONLY public."Invitation"
ADD CONSTRAINT fk_invitation_dmp FOREIGN KEY ("Dmp") REFERENCES public."DMP"("ID");
\ No newline at end of file
CREATE TABLE public."UserPreference" (
"Id" uuid NOT NULL,
"UserId" uuid NOT NULL,
"Data" json NOT NULL,
"PreferenceType" smallint NOT NULL
);
ALTER TABLE public."UserPreference" OWNER TO :POSTGRES_USER;
ALTER TABLE ONLY public."UserPreference"
ADD CONSTRAINT "UserPreference_pkey" PRIMARY KEY ("Id");
ALTER TABLE ONLY public."UserPreference"
ADD CONSTRAINT userpreference_user_fk FOREIGN KEY ("UserId") REFERENCES public."UserInfo"(id);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment