-- 将旧表 biz_shop_manage 的 group_name 数据回填到新分组表与 group_id 字段

INSERT INTO biz_shop_manage_group (group_name)
SELECT DISTINCT sm.group_name
FROM biz_shop_manage sm
LEFT JOIN biz_shop_manage_group g ON g.group_name = sm.group_name
WHERE sm.group_name IS NOT NULL
  AND TRIM(sm.group_name) <> ''
  AND g.id IS NULL;

UPDATE biz_shop_manage sm
JOIN biz_shop_manage_group g ON g.group_name = sm.group_name
SET sm.group_id = g.id
WHERE sm.group_id IS NULL
  AND sm.group_name IS NOT NULL
  AND TRIM(sm.group_name) <> '';
