-- v3.5.8 补丁：删除门店分类权限（可对已执行过 migrate-hq-permissions-v358.sql 的库单独跑）
-- 城市门店服务可新增分类，不可删除

INSERT IGNORE INTO `hq_role_permission` (`admin_role`, `permission_key`, `created_at`)
SELECT `admin_role`, 'store_categories_delete', NOW(3)
FROM `hq_role_permission`
WHERE `permission_key` = 'store_categories'
  AND `admin_role` <> 'CITY_STORE_SERVICE';

INSERT IGNORE INTO `hq_account_permission` (`hq_account_id`, `permission_key`, `effect`, `created_at`)
SELECT p.`hq_account_id`, 'store_categories_delete', p.`effect`, NOW(3)
FROM `hq_account_permission` p
INNER JOIN `hq_account` a ON a.`id` = p.`hq_account_id`
WHERE p.`permission_key` = 'store_categories'
  AND a.`admin_role` <> 'CITY_STORE_SERVICE';
