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

        ALTER TABLE public."Tasks" ADD "ParentId" bigint NULL;
	ALTER TABLE public."Tasks" ADD "OwnerId" bigint NULL;
	UPDATE public."Tasks" SET "OwnerId" = "UserId";
	CREATE INDEX "IDX_Tasks_OwnerId-UserId-Type-Status"
    		ON public."Tasks" USING btree
    		("OwnerId" ASC NULLS LAST, "UserId" ASC NULLS LAST, "Status" ASC NULLS LAST, "Type" ASC NULLS LAST)
    		TABLESPACE pg_default; 
        EXCEPTION
            WHEN OTHERS THEN RAISE NOTICE 'Alter OwnerId table <Tasks> error.';
        END;
    END;
$$

