ALTER TABLE sys_menus
    ALTER COLUMN path DROP NOT NULL;

ALTER TABLE sys_menus
    DROP CONSTRAINT IF EXISTS sys_menus_path_key;

DROP INDEX IF EXISTS sys_menus_path_unique_idx;

CREATE UNIQUE INDEX sys_menus_path_unique_idx
    ON sys_menus (path)
    WHERE type IN (0, 1);

ALTER TABLE sys_menus
    DROP CONSTRAINT IF EXISTS sys_menus_path_required_check;

ALTER TABLE sys_menus
    ADD CONSTRAINT sys_menus_path_required_check
        CHECK (type = 2 OR path IS NOT NULL);