DO $$
    DECLARE
        _path character varying(256) := 'patch-2025_11_12-ProjectAttributes_Type';
    BEGIN
        IF EXISTS (SELECT 1 FROM public."Versions" WHERE "Path" = _path) THEN
            RETURN;
        END IF;

        IF EXISTS (SELECT 1 FROM public."Versions" WHERE "Build" >= 15634) THEN
            RETURN;
        END IF;

        BEGIN
            alter table public."ProjectAttributes" add column "Type" INT not null default 0;

            ALTER TABLE public."ProjectAttributes" DROP CONSTRAINT "ProjectAttributes_pkey";
            ALTER TABLE public."ProjectAttributes" ADD PRIMARY KEY ("Name", "ValueType", "Type");

            INSERT INTO public."Versions" ("Path", "Build") VALUES (_path, 0);

        EXCEPTION
            WHEN OTHERS THEN
                RAISE NOTICE '[ERR] %: %', _path, SQLERRM;
        END;
    END;
$$;
