DO $$DECLARE this_version CONSTANT varchar := '00.01.001'; BEGIN PERFORM * FROM "DBVersion" WHERE version = this_version; IF FOUND THEN RETURN; END IF; ALTER TABLE public."DescriptionTemplateType" RENAME "ID" TO id; ALTER TABLE public."DescriptionTemplateType" RENAME "Name" TO name; ALTER TABLE public."DescriptionTemplateType" RENAME "Status" TO status; ALTER TABLE public."DescriptionTemplateType" ADD COLUMN created_at timestamp without time zone; ALTER TABLE public."DescriptionTemplateType" ADD COLUMN updated_at timestamp without time zone; UPDATE public."DescriptionTemplateType" SET created_at = now(); UPDATE public."DescriptionTemplateType" SET updated_at = now(); ALTER TABLE public."DescriptionTemplateType" ALTER COLUMN created_at SET NOT NULL; ALTER TABLE public."DescriptionTemplateType" ALTER COLUMN updated_at SET NOT NULL; ALTER TABLE public."DescriptionTemplateType" ADD COLUMN is_active smallint; UPDATE public."DescriptionTemplateType" SET is_active = 1; UPDATE public."DescriptionTemplateType" SET is_active = 0 where status = 99; UPDATE public."DescriptionTemplateType" SET status = 0 where is_active = 0; ALTER TABLE public."DescriptionTemplateType" ALTER COLUMN is_active SET NOT NULL; INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.001', '2023-10-19 12:00:00.000000+02', now(), 'Align Description Template Type.'); END$$;