ALTER TABLE public."DescriptionTemplate" RENAME "ID" TO id;

ALTER TABLE public."DescriptionTemplate" RENAME "Label" TO label;

ALTER TABLE public."DescriptionTemplate" RENAME "Definition" TO definition;

ALTER TABLE public."DescriptionTemplate" RENAME "Status" TO status;

ALTER TABLE public."DescriptionTemplate" RENAME "Created" TO created_at;

ALTER TABLE public."DescriptionTemplate" RENAME "Modified" TO updated_at;

ALTER TABLE public."DescriptionTemplate" RENAME "Description" TO description;

ALTER TABLE public."DescriptionTemplate" RENAME "GroupId" TO group_id;

ALTER TABLE public."DescriptionTemplate" RENAME "Version" TO version;

ALTER TABLE public."DescriptionTemplate" RENAME "Language" TO "language";

ALTER TABLE public."DescriptionTemplate" RENAME "Type" TO "type";

ALTER TABLE public."DescriptionTemplate" ALTER COLUMN created_at TYPE timestamp without time zone ;

ALTER TABLE public."DescriptionTemplate" ALTER COLUMN updated_at TYPE timestamp without time zone ;

ALTER TABLE public."DescriptionTemplate" ADD COLUMN is_active smallint;

UPDATE public."DescriptionTemplate" SET is_active = 1;

UPDATE public."DescriptionTemplate" SET is_active = 0 where status = 99;
UPDATE public."DescriptionTemplate" SET status = 0 where is_active = 0;

ALTER TABLE public."DescriptionTemplate" ALTER COLUMN is_active SET NOT NULL;

ALTER TABLE public."DescriptionTemplate" ADD COLUMN version_status smallint;

UPDATE public."DescriptionTemplate" SET version_status = 1;

UPDATE public."DescriptionTemplate" SET version_status = 0 where id in (
	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
	)
);

ALTER TABLE public."DescriptionTemplate" ALTER COLUMN version_status SET NOT NULL;