-- 为 yifan_naming_reports 表添加 uuid 字段
ALTER TABLE yifan_naming_reports 
ADD COLUMN uuid VARCHAR(64) NOT NULL DEFAULT '' COMMENT 'UUID全局唯一标识' AFTER id;

-- 为现有数据生成 UUID
UPDATE yifan_naming_reports 
SET uuid = CONCAT(
    SUBSTRING(MD5(CONCAT(id, RAND())), 1, 8), '-',
    SUBSTRING(MD5(CONCAT(id, RAND())), 9, 4), '-',
    SUBSTRING(MD5(CONCAT(id, RAND())), 13, 4), '-',
    SUBSTRING(MD5(CONCAT(id, RAND())), 17, 4), '-',
    SUBSTRING(MD5(CONCAT(id, RAND())), 21, 12)
)
WHERE uuid = '';

-- 添加唯一索引
ALTER TABLE yifan_naming_reports 
ADD UNIQUE INDEX uk_uuid (uuid);
