DO $$DECLARE
   this_version CONSTANT varchar := '00.01.059';
BEGIN
   PERFORM * FROM "DBVersion" WHERE version = this_version;
   IF FOUND THEN RETURN; END IF;

ALTER TABLE public."ant_Annotation" ADD COLUMN "subject_id" uuid NOT NULL;

ALTER TABLE public."ant_Annotation" ADD COLUMN "thread_id" uuid;

ALTER TABLE public."ant_Annotation" ADD COLUMN "parent_id" uuid;

ALTER TABLE public."ant_Annotation" ADD COLUMN "protection_type" smallint NOT NULL;

ALTER TABLE public."ant_Annotation" ADD COLUMN "time_stamp" timestamp without time zone NOT NULL;

ALTER TABLE public."ant_Annotation" ADD CONSTRAINT "ant_Annotation_user_fkey" FOREIGN KEY ("subject_id")
        REFERENCES public."ant_User" (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION;

ALTER TABLE public."ant_Annotation" ADD CONSTRAINT "ant_Annotation_parent_fkey" FOREIGN KEY ("parent_id")
        REFERENCES public."ant_Annotation" (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION;

INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.059', '2024-03-07 12:00:00.000000+02', now(), 'Add columns on ant_Annotaion table.');

END$$;