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

39 lines
1.6 KiB
MySQL
Raw Normal View History

2023-11-22 12:31:00 +01:00
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";
2023-10-31 16:24:03 +01:00
2023-11-22 12:31:00 +01:00
ALTER TABLE public."UserDescriptionTemplate" RENAME usr TO "user";
2023-10-31 16:24:03 +01:00
2023-11-22 12:31:00 +01:00
ALTER TABLE public."UserDescriptionTemplate" RENAME "descriptionTemplate" TO description_template;
2023-10-31 16:24:03 +01:00
2023-11-22 12:31:00 +01:00
ALTER TABLE public."UserDescriptionTemplate" ALTER COLUMN "role" TYPE smallint;
ALTER TABLE public."UserDescriptionTemplate" ALTER COLUMN "role" SET NOT NULL;
2023-10-31 16:24:03 +01:00
2023-11-22 12:31:00 +01:00
ALTER TABLE public."UserDescriptionTemplate" ADD COLUMN updated_at timestamp without time zone;
2023-10-31 16:24:03 +01:00
2023-11-22 12:31:00 +01:00
ALTER TABLE public."UserDescriptionTemplate" ADD COLUMN created_at timestamp without time zone;
2023-10-31 16:24:03 +01:00
2023-11-22 12:31:00 +01:00
ALTER TABLE public."UserDescriptionTemplate" ADD COLUMN is_active smallint;
2023-10-31 16:24:03 +01:00
2023-11-22 12:31:00 +01:00
UPDATE public."UserDescriptionTemplate" SET is_active = 1;
2023-10-31 16:24:03 +01:00
2023-11-22 12:31:00 +01:00
UPDATE public."UserDescriptionTemplate" SET is_active = 0 where role = 2;
UPDATE public."UserDescriptionTemplate" SET role = 1 where is_active = 0;
2023-10-31 16:24:03 +01:00
2023-11-22 12:31:00 +01:00
ALTER TABLE public."UserDescriptionTemplate" ALTER COLUMN is_active SET NOT NULL;
2023-10-31 16:24:03 +01:00
2023-11-22 12:31:00 +01:00
UPDATE public."UserDescriptionTemplate" SET updated_at = now() at time zone 'utc';
2023-10-31 16:24:03 +01:00
2023-11-22 12:31:00 +01:00
ALTER TABLE public."UserDescriptionTemplate" ALTER COLUMN updated_at SET NOT NULL;
2023-10-31 16:24:03 +01:00
2023-11-22 12:31:00 +01:00
UPDATE public."UserDescriptionTemplate" SET created_at = now() at time zone 'utc';
2023-10-31 16:24:03 +01:00
2023-11-22 12:31:00 +01:00
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$$;