Quellcode durchsuchen

fix: 迁移 SQL 改为先删后写,ID 使用 91001+ 避免冲突

- DELETE 清理旧菜单和角色关联后再 INSERT
- t_role_menu.id 改用 91001-91003 避开已有的 90053-90055
- seed_menu.sql 同步更新

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
skyline vor 1 Woche
Ursprung
Commit
0bb880869b
2 geänderte Dateien mit 19 neuen und 18 gelöschten Zeilen
  1. 18 17
      docs/database/migrate_replenishment_to_inventory.sql
  2. 1 1
      docs/database/seed_menu.sql

+ 18 - 17
docs/database/migrate_replenishment_to_inventory.sql

@@ -1,22 +1,23 @@
 -- 将「设备补货单」模块添加到「库存管理」下
--- ============================================
--- 菜单 (已执行成功则跳过)
--- ============================================
-INSERT IGNORE INTO t_menu (id, parent_id, menu_type, title, name, path, component, `rank`, icon, show_link, show_parent, `redirect`, keep_alive)
-VALUES (505, 500, 0, '设备补货单', 'ReplenishmentOrder', '/inventory/replenishment-order', '', 4, 'ep:shopping-cart', 1, 0, '/inventory/replenishment-order/list', 1);
+-- 使用大 ID (91000+) 避免与种子数据冲突
+
+-- 1. 清理旧数据
+DELETE FROM t_role_menu WHERE role_id = 1 AND menu_id IN (505, 506, 507);
+DELETE FROM t_menu WHERE id IN (505, 506, 507);
+DELETE FROM t_role_menu WHERE id IN (91001, 91002, 91003);
 
-INSERT IGNORE INTO t_menu (id, parent_id, menu_type, title, name, path, component, `rank`, show_link, show_parent)
-VALUES (506, 505, 0, '补货单列表', 'ReplenishmentOrderList', '/inventory/replenishment-order/list', 'replenishment-order/index', 1, 1, 0);
+-- 2. 写入菜单
+INSERT INTO t_menu (id, parent_id, menu_type, title, name, path, component, `rank`, icon, show_link, show_parent, `redirect`, keep_alive)
+VALUES (505, 500, 0, '设备补货单', 'ReplenishmentOrder', '/inventory/replenishment-order', '', 4, 'ep:shopping-cart', 1, 0, '/inventory/replenishment-order/list', 1);
 
-INSERT IGNORE INTO t_menu (id, parent_id, menu_type, title, name, path, component, `rank`, show_link, show_parent)
-VALUES (507, 505, 0, '补货单详情', 'ReplenishmentOrderDetail', '/inventory/replenishment-order/detail', 'replenishment-order/detail', 2, 0, 0);
+INSERT INTO t_menu (id, parent_id, menu_type, title, name, path, component, `rank`, show_link, show_parent)
+VALUES
+(506, 505, 0, '补货单列表', 'ReplenishmentOrderList', '/inventory/replenishment-order/list', 'replenishment-order/index', 1, 1, 0),
+(507, 505, 0, '补货单详情', 'ReplenishmentOrderDetail', '/inventory/replenishment-order/detail', 'replenishment-order/detail', 2, 0, 0);
 
--- ============================================
--- 角色菜单关联 (自动生成不冲突的 ID)
--- ============================================
+-- 3. 写入角色菜单关联
 INSERT INTO t_role_menu (id, role_id, menu_id, create_time)
-SELECT t.max_id + (@rn := @rn + 1), 1, src.menu_id, NOW()
-FROM (SELECT 505 AS menu_id UNION ALL SELECT 506 UNION ALL SELECT 507) src
-CROSS JOIN (SELECT @rn := 0) r
-CROSS JOIN (SELECT COALESCE(MAX(id), 0) AS max_id FROM t_role_menu) t
-WHERE NOT EXISTS (SELECT 1 FROM t_role_menu rm WHERE rm.role_id = 1 AND rm.menu_id = src.menu_id);
+VALUES
+(91001, 1, 505, NOW()),
+(91002, 1, 506, NOW()),
+(91003, 1, 507, NOW());

+ 1 - 1
docs/database/seed_menu.sql

@@ -185,7 +185,7 @@ INSERT INTO t_role_menu (id, role_id, menu_id) VALUES
 (90003, 1, 200), (90004, 1, 201), (90005, 1, 202),
 (90006, 1, 300), (90007, 1, 301), (90008, 1, 302), (90009, 1, 303), (90010, 1, 304),
 (90011, 1, 400), (90012, 1, 401), (90013, 1, 402),
-(90014, 1, 500), (90015, 1, 501), (90016, 1, 502), (90017, 1, 503), (90053, 1, 505), (90054, 1, 506), (90055, 1, 507),
+(90014, 1, 500), (90015, 1, 501), (90016, 1, 502), (90017, 1, 503), (91001, 1, 505), (91002, 1, 506), (91003, 1, 507),
 (90018, 1, 600), (90019, 1, 601),
 (90020, 1, 700), (90021, 1, 701), (90022, 1, 702), (90023, 1, 703), (90024, 1, 704), (90025, 1, 705), (90026, 1, 706), (90027, 1, 707),
 (90028, 1, 800), (90029, 1, 801), (90030, 1, 802), (90031, 1, 803), (90032, 1, 804),