admin/sql/fix_data_perm_menu_invalid_guids.sql
2026-07-03 11:58:24 +08:00

26 lines
876 B
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 修复 menu 表非法 GUID(Id/PId 含非十六进制字符,如 dp100001 中的 p)
-- 症状:登录 / get-menu-tree → Could not parse CHAR(36) value as Guid: dp100001-...
-- GUID 仅允许 0-9、a-f
--
-- ⚠️ 在 RBAC 库执行
SELECT 'before fix' AS stage, `Id`, `PId`, `Name`, `Route`, `PermissionCode`
FROM `menu`
WHERE `Id` LIKE 'dp100001-%'
OR `PId` LIKE 'dp100001-%';
-- 先改子节点 PId,再改 Id
UPDATE `menu`
SET `PId` = REPLACE(`PId`, 'dp100001-', 'da100001-')
WHERE `PId` LIKE 'dp100001-%';
UPDATE `menu`
SET `Id` = REPLACE(`Id`, 'dp100001-', 'da100001-')
WHERE `Id` LIKE 'dp100001-%';
SELECT 'after fix (should be empty)' AS stage, `Id`, `PId`, `Name`, `Route`
FROM `menu`
WHERE `Id` LIKE 'dp100001-%'
OR `PId` LIKE 'dp100001-%'
OR (`Id` NOT REGEXP '^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$');