-- 清理员工实体关系历史旧数据
-- 说明：删除当前无法匹配任何员工亲属关系（is_emp_family = 1）的旧实体关联记录
-- 执行方式：bin/mysql_utf8_exec.sh sql/migration/2026-04-23-clean-legacy-staff-enterprise-relation-data.sql

DELETE ser
FROM ccdi_staff_enterprise_relation ser
LEFT JOIN ccdi_staff_fmy_relation sfr
       ON ser.person_id = sfr.relation_cert_no
      AND sfr.is_emp_family = 1
WHERE sfr.id IS NULL;
