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

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

        BEGIN
            IF NOT EXISTS(
                SELECT 1
                FROM information_schema.columns
                WHERE table_schema = 'public'
                  AND table_name = 'Files'
                  AND column_name = 'IsLocal') THEN
                ALTER TABLE public."Files" ADD COLUMN "IsLocal" boolean DEFAULT FALSE NOT NULL;
            END IF;

            INSERT INTO public."Versions" ("Path", "Build") VALUES (_path, 0);
        EXCEPTION
            WHEN OTHERS THEN
                RAISE NOTICE '[ERR] %: %', _path, SQLERRM;
        END;
    END;
$$;