DO $$ 
    BEGIN
          IF EXISTS (SELECT "Id" FROM public."Versions" WHERE "Build">=1765) THEN
		RETURN;
          END IF;
        BEGIN
		DROP INDEX "IDX_EmailMessages_MessageId_Id";
		ALTER TABLE public."EmailMessages" DROP COLUMN "MessageId";
 		ALTER TABLE public."EmailMessages" ADD "MessageId" character varying(256) NULL;

CREATE INDEX "IDX_EmailMessages_MessageId_Id"
    ON public."EmailMessages" USING btree
    ("MessageId" ASC NULLS LAST,"Id" ASC NULLS LAST)
    TABLESPACE pg_default; 

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



