SET NAMES utf8mb4;

-- 已同时持有正式删除权限的角色先移除重复旧映射，避免唯一索引冲突。
DELETE legacy_mapping
FROM `tb_sys_role_menu` legacy_mapping
INNER JOIN `tb_sys_role_menu` canonical_mapping
  ON canonical_mapping.`role_id` = legacy_mapping.`role_id`
 AND canonical_mapping.`menu_id` = 367400000000000018
WHERE legacy_mapping.`menu_id` = 367400000000000015;

-- 保留已部署环境中对旧删除入口的显式角色授权，并迁移到真实审批/删除入口。
UPDATE `tb_sys_role_menu`
SET `menu_id` = 367400000000000018
WHERE `menu_id` = 367400000000000015;

-- 删除没有对应 Controller 的历史权限菜单。
DELETE FROM `tb_sys_menu`
WHERE `id` = 367400000000000015
  AND `permission_tag` = '/api/v1/skill/remove';

-- 真实入口会根据审批配置提交审批或直接删除，统一使用一个操作权限。
UPDATE `tb_sys_menu`
SET `menu_title` = '删除',
    `sort_no` = 5,
    `modified` = CURRENT_TIMESTAMP,
    `modified_by` = 1,
    `remark` = 'Skill-删除（审批或直接执行）'
WHERE `id` = 367400000000000018
  AND `permission_tag` = '/api/v1/skill/submitDeleteApproval';
