add more sql scripts

This commit is contained in:
amentis 2023-12-06 14:23:21 +02:00
parent 908c530922
commit 46dccbfbdb
3 changed files with 249 additions and 0 deletions

View File

@ -0,0 +1,30 @@
DO $$DECLARE
this_version CONSTANT varchar := '00.01.036';
BEGIN
PERFORM * FROM "DBVersion" WHERE version = this_version;
IF FOUND THEN RETURN; END IF;
CREATE TABLE public."TenantUser"
(
id uuid NOT NULL,
"user" uuid NOT NULL,
tenant uuid NOT NULL,
is_active smallint NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
CONSTRAINT "TenantUser_pkey" PRIMARY KEY (id),
CONSTRAINT "TenantUser_tenant_fkey" FOREIGN KEY (tenant)
REFERENCES public."Tenant" (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID,
CONSTRAINT "TenantUser_user_fkey" 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.036', '2023-12-06 12:00:00.000000+02', now(), 'Add table TenantUser.');
END$$;

View File

@ -0,0 +1,12 @@
DO $$DECLARE
this_version CONSTANT varchar := '00.01.037';
BEGIN
PERFORM * FROM "DBVersion" WHERE version = this_version;
IF FOUND THEN RETURN; END IF;
ALTER TABLE public.usersettings
RENAME TO "UserSettings";
INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.037', '2023-12-06 12:00:00.000000+02', now(), 'Rename usersettings Table to UserSettings.');
END$$;

View File

@ -0,0 +1,207 @@
DO $$DECLARE
this_version CONSTANT varchar := '00.01.038';
BEGIN
PERFORM * FROM "DBVersion" WHERE version = this_version;
IF FOUND THEN RETURN; END IF;
ALTER TABLE public."Description"
ADD COLUMN tenant uuid;
ALTER TABLE public."Description"
ADD CONSTRAINT "Description_tenant_fkey" FOREIGN KEY (tenant)
REFERENCES public."Tenant" (id)
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."DescriptionReference"
ADD COLUMN tenant uuid;
ALTER TABLE public."DescriptionReference"
ADD CONSTRAINT "DescriptionReference_tenant_fkey" FOREIGN KEY (tenant)
REFERENCES public."Tenant" (id)
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."DescriptionTag"
ADD COLUMN tenant uuid;
ALTER TABLE public."DescriptionTag"
ADD CONSTRAINT "DescriptionTag_tenant_fkey" FOREIGN KEY (tenant)
REFERENCES public."Tenant" (id)
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."DescriptionTemplate"
ADD COLUMN tenant uuid;
ALTER TABLE public."DescriptionTemplate"
ADD CONSTRAINT "DescriptionTemplate_tenant_fkey" FOREIGN KEY (tenant)
REFERENCES public."Tenant" (id)
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."DescriptionTemplateType"
ADD COLUMN tenant uuid;
ALTER TABLE public."DescriptionTemplateType"
ADD CONSTRAINT "DescriptionTemplateType_tenant_fkey" FOREIGN KEY (tenant)
REFERENCES public."Tenant" (id)
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."DmpBlueprint"
ADD COLUMN tenant uuid;
ALTER TABLE public."DmpBlueprint"
ADD CONSTRAINT "DmpBlueprint_tenant_fkey" FOREIGN KEY (tenant)
REFERENCES public."Tenant" (id)
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."DmpDescriptionTemplate"
ADD COLUMN tenant uuid;
ALTER TABLE public."DmpDescriptionTemplate"
ADD CONSTRAINT "DmpDescriptionTemplate_tenant_fkey" FOREIGN KEY (tenant)
REFERENCES public."Tenant" (id)
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."Dmp"
ADD COLUMN tenant uuid;
ALTER TABLE public."Dmp"
ADD CONSTRAINT "Dmp_tenant_fkey" FOREIGN KEY (tenant)
REFERENCES public."Tenant" (id)
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."DmpReference"
ADD COLUMN tenant uuid;
ALTER TABLE public."DmpReference"
ADD CONSTRAINT "DmpReference_tenant_fkey" FOREIGN KEY (tenant)
REFERENCES public."Tenant" (id)
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."DmpUser"
ADD COLUMN tenant uuid;
ALTER TABLE public."DmpUser"
ADD CONSTRAINT "DmpUser_tenant_fkey" FOREIGN KEY (tenant)
REFERENCES public."Tenant" (id)
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."EntityDoi"
ADD COLUMN tenant uuid;
ALTER TABLE public."EntityDoi"
ADD CONSTRAINT "EntityDoi_tenant_fkey" FOREIGN KEY (tenant)
REFERENCES public."Tenant" (id)
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."Language"
ADD COLUMN tenant uuid;
ALTER TABLE public."Language"
ADD CONSTRAINT "Language_tenant_fkey" FOREIGN KEY (tenant)
REFERENCES public."Tenant" (id)
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."Reference"
ADD COLUMN tenant uuid;
ALTER TABLE public."Reference"
ADD CONSTRAINT "Reference_tenant_fkey" FOREIGN KEY (tenant)
REFERENCES public."Tenant" (id)
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."ReferenceType"
ADD COLUMN tenant uuid;
ALTER TABLE public."ReferenceType"
ADD CONSTRAINT "ReferenceType_tenant_fkey" FOREIGN KEY (tenant)
REFERENCES public."Tenant" (id)
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."StorageFile"
ADD COLUMN tenant uuid;
ALTER TABLE public."StorageFile"
ADD CONSTRAINT "StorageFile_tenant_fkey" FOREIGN KEY (tenant)
REFERENCES public."Tenant" (id)
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."SupportiveMaterial"
ADD COLUMN tenant uuid;
ALTER TABLE public."SupportiveMaterial"
ADD CONSTRAINT "SupportiveMaterial_tenant_fkey" FOREIGN KEY (tenant)
REFERENCES public."Tenant" (id)
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."Tag"
ADD COLUMN tenant uuid;
ALTER TABLE public."Tag"
ADD CONSTRAINT "Tag_tenant_fkey" FOREIGN KEY (tenant)
REFERENCES public."Tenant" (id)
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."UserContactInfo"
ADD COLUMN tenant uuid;
ALTER TABLE public."UserContactInfo"
ADD CONSTRAINT "UserContactInfo_tenant_fkey" FOREIGN KEY (tenant)
REFERENCES public."Tenant" (id)
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."UserCredential"
ADD COLUMN tenant uuid;
ALTER TABLE public."UserCredential"
ADD CONSTRAINT "UserCredential_tenant_fkey" FOREIGN KEY (tenant)
REFERENCES public."Tenant" (id)
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."UserDescriptionTemplate"
ADD COLUMN tenant uuid;
ALTER TABLE public."UserDescriptionTemplate"
ADD CONSTRAINT "UserDescriptionTemplate_tenant_fkey" FOREIGN KEY (tenant)
REFERENCES public."Tenant" (id)
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."UserRole"
ADD COLUMN tenant uuid;
ALTER TABLE public."UserRole"
ADD CONSTRAINT "UserRole_tenant_fkey" FOREIGN KEY (tenant)
REFERENCES public."Tenant" (id)
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."UserSettings"
ADD COLUMN tenant uuid;
ALTER TABLE public."UserSettings"
ADD CONSTRAINT "UserSettings_tenant_fkey" FOREIGN KEY (tenant)
REFERENCES public."Tenant" (id)
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.038', '2023-12-06 12:00:00.000000+02', now(), 'Add Tenant Id to tables.');
END$$;