argos/dmp-db-scema/updates/00.01.011_Align_UserDescrip...

39 lines
1.6 KiB
SQL

DO $$DECLARE
this_version CONSTANT varchar := '00.01.011';
BEGIN
PERFORM * FROM "DBVersion" WHERE version = this_version;
IF FOUND THEN RETURN; END IF;
ALTER TABLE public."UserDatasetProfile" RENAME TO "UserDescriptionTemplate";
ALTER TABLE public."UserDescriptionTemplate" RENAME usr TO "user";
ALTER TABLE public."UserDescriptionTemplate" RENAME "descriptionTemplate" TO description_template;
ALTER TABLE public."UserDescriptionTemplate" ALTER COLUMN "role" TYPE smallint;
ALTER TABLE public."UserDescriptionTemplate" ALTER COLUMN "role" SET NOT NULL;
ALTER TABLE public."UserDescriptionTemplate" ADD COLUMN updated_at timestamp without time zone;
ALTER TABLE public."UserDescriptionTemplate" ADD COLUMN created_at timestamp without time zone;
ALTER TABLE public."UserDescriptionTemplate" ADD COLUMN is_active smallint;
UPDATE public."UserDescriptionTemplate" SET is_active = 1;
UPDATE public."UserDescriptionTemplate" SET is_active = 0 where role = 2;
UPDATE public."UserDescriptionTemplate" SET role = 1 where is_active = 0;
ALTER TABLE public."UserDescriptionTemplate" ALTER COLUMN is_active SET NOT NULL;
UPDATE public."UserDescriptionTemplate" SET updated_at = now() at time zone 'utc';
ALTER TABLE public."UserDescriptionTemplate" ALTER COLUMN updated_at SET NOT NULL;
UPDATE public."UserDescriptionTemplate" SET created_at = now() at time zone 'utc';
ALTER TABLE public."UserDescriptionTemplate" ALTER COLUMN created_at SET NOT NULL;
INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.011', '2023-11-02 12:00:00.000000+02', now(), 'Aling UserDescriptionTemplate table (former UserDatasetProfile).');
END$$;