argos/dmp-db-scema/updates/00.01.010_Align_Description...

72 lines
2.5 KiB
MySQL
Raw Permalink Normal View History

2023-11-23 13:40:44 +01:00
DO $$DECLARE
this_version CONSTANT varchar := '00.01.010';
BEGIN
PERFORM * FROM "DBVersion" WHERE version = this_version;
IF FOUND THEN RETURN; END IF;
ALTER TABLE public."DescriptionTemplate" RENAME "ID" TO id;
2023-10-27 17:46:34 +02:00
2023-11-23 13:40:44 +01:00
ALTER TABLE public."DescriptionTemplate" RENAME "Label" TO label;
2023-10-27 17:46:34 +02:00
2023-11-23 13:40:44 +01:00
ALTER TABLE public."DescriptionTemplate" RENAME "Definition" TO definition;
2023-10-27 17:46:34 +02:00
2023-11-23 13:40:44 +01:00
ALTER TABLE public."DescriptionTemplate" RENAME "Status" TO status;
2023-10-27 17:46:34 +02:00
2023-11-23 13:40:44 +01:00
ALTER TABLE public."DescriptionTemplate" RENAME "Created" TO created_at;
2023-10-27 17:46:34 +02:00
2023-11-23 13:40:44 +01:00
ALTER TABLE public."DescriptionTemplate" RENAME "Modified" TO updated_at;
2023-10-27 17:46:34 +02:00
2023-11-23 13:40:44 +01:00
ALTER TABLE public."DescriptionTemplate" RENAME "Description" TO description;
2023-10-27 17:46:34 +02:00
2023-11-23 13:40:44 +01:00
ALTER TABLE public."DescriptionTemplate" RENAME "GroupId" TO group_id;
2023-10-27 17:46:34 +02:00
2023-11-23 13:40:44 +01:00
ALTER TABLE public."DescriptionTemplate" RENAME "Version" TO version;
2023-10-27 17:46:34 +02:00
2023-11-23 13:40:44 +01:00
ALTER TABLE public."DescriptionTemplate" RENAME "Language" TO "language";
2023-10-27 17:46:34 +02:00
2023-11-23 13:40:44 +01:00
ALTER TABLE public."DescriptionTemplate" RENAME "Type" TO "type";
2023-10-27 17:46:34 +02:00
2023-11-23 13:40:44 +01:00
ALTER TABLE public."DescriptionTemplate" ALTER COLUMN created_at TYPE timestamp without time zone ;
2023-10-27 17:46:34 +02:00
2023-11-23 13:40:44 +01:00
ALTER TABLE public."DescriptionTemplate" ALTER COLUMN updated_at TYPE timestamp without time zone ;
2023-10-27 17:46:34 +02:00
2023-11-23 13:40:44 +01:00
ALTER TABLE public."DescriptionTemplate" ALTER COLUMN group_id DROP DEFAULT;
2023-11-22 12:31:00 +01:00
2023-11-23 13:40:44 +01:00
ALTER TABLE public."DescriptionTemplate" ADD COLUMN is_active smallint;
2023-10-27 17:46:34 +02:00
2023-11-23 13:40:44 +01:00
UPDATE public."DescriptionTemplate" SET is_active = 1;
2023-10-27 17:46:34 +02:00
2023-11-23 13:40:44 +01:00
UPDATE public."DescriptionTemplate" SET is_active = 0 where status = 99;
UPDATE public."DescriptionTemplate" SET status = 0 where is_active = 0;
2023-10-27 17:46:34 +02:00
2023-11-23 13:40:44 +01:00
ALTER TABLE public."DescriptionTemplate" ALTER COLUMN is_active SET NOT NULL;
2023-11-23 13:40:44 +01:00
ALTER TABLE public."DescriptionTemplate" ADD COLUMN version_status smallint;
2023-11-23 13:40:44 +01:00
UPDATE public."DescriptionTemplate" SET version_status = 1;
2023-11-23 13:40:44 +01:00
UPDATE public."DescriptionTemplate" SET version_status = 0 where id in (
2024-03-11 17:32:21 +01:00
select dt.id from public."DescriptionTemplate" as dt
where dt.version =
(
select Max(f.version)
from public."DescriptionTemplate" as f where f.group_id=dt.group_id and f.status = 1
)
);
2024-03-12 15:28:07 +01:00
UPDATE public."DescriptionTemplate" SET version_status = 2 where status = 0 and id in (
2023-11-23 13:40:44 +01:00
select dt.id from public."DescriptionTemplate" as dt
where dt.version =
(
select Max(f.version)
from public."DescriptionTemplate" as f where f.group_id=dt.group_id
)
);
2023-11-23 13:40:44 +01:00
ALTER TABLE public."DescriptionTemplate" ALTER COLUMN version_status SET NOT NULL;
ALTER TABLE public."DescriptionTemplate" ALTER COLUMN version DROP DEFAULT;
2023-11-23 13:40:44 +01:00
INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.010', '2023-11-02 12:00:00.000000+02', now(), 'Aling DescriptionTemplate table.');
END$$;