DO $$ 
    BEGIN
          IF EXISTS (SELECT "Id" FROM public."Versions" WHERE "Build">=2637) THEN
		RETURN;
          END IF;
        BEGIN

       	ALTER TABLE public."EmailMessages" ADD "ThreadId" character varying(256)  NULL; 

	CREATE INDEX "IDX_EmailMessages_ThreadId_OwnerId"
   	 ON public."EmailMessages" USING btree
   	 ("ThreadId" ASC NULLS LAST,"OwnerId" ASC NULLS LAST)
    	TABLESPACE pg_default; 

        EXCEPTION
            WHEN OTHERS THEN RAISE NOTICE 'Alter ThreadId EmailMessages <Tasks> error.';
        END;
    END;
$$

