-- 기존 DB: 메뉴(mm_link)의 admin/* 업무 URL 을 bag/* 로 일괄 변경
-- site·admin 타입 모두 대상. 실행 전 백업 권장.
-- 포장 단위 CRUD 는 bag/packaging-units/manage 로 통일.

SET NAMES utf8mb4;

UPDATE `menu` m
INNER JOIN `menu_type` mt ON m.mt_idx = mt.mt_idx AND mt.mt_code = 'site'
SET m.mm_link = CASE
  WHEN m.mm_link LIKE 'admin/packaging-units%' THEN REPLACE(m.mm_link, 'admin/packaging-units', 'bag/packaging-units/manage')
  WHEN m.mm_link LIKE 'admin/%' THEN REPLACE(m.mm_link, 'admin/', 'bag/')
  ELSE m.mm_link
END
WHERE m.mm_link LIKE 'admin/%';

-- 관리자 상단 메뉴: 순수 관리(회원·역할 등)는 유지하고, 업무 모듈 링크만 bag 으로 이동
UPDATE `menu` m
INNER JOIN `menu_type` mt ON m.mt_idx = mt.mt_idx AND mt.mt_code = 'admin'
SET m.mm_link = CASE
  WHEN m.mm_link LIKE 'admin/packaging-units%' THEN REPLACE(m.mm_link, 'admin/packaging-units', 'bag/packaging-units/manage')
  WHEN m.mm_link REGEXP '^admin/(managers|sales-agencies|companies|free-recipients|designated-shops|bag-prices|bag-orders|bag-receivings|bag-inventory|shop-orders|bag-sales|bag-issues|reports|password-change)(/|$)'
    THEN REPLACE(m.mm_link, 'admin/', 'bag/')
  ELSE m.mm_link
END
WHERE m.mm_link LIKE 'admin/packaging-units%'
   OR m.mm_link REGEXP '^admin/(managers|sales-agencies|companies|free-recipients|designated-shops|bag-prices|bag-orders|bag-receivings|bag-inventory|shop-orders|bag-sales|bag-issues|reports|password-change)(/|$)';
