-- V17: 拆分 UgcWork.status 字段
-- 原 status (INT) 同时承载「乐读派创作进度」和「本地发布状态」，导致前端筛选失败
-- 拆为：leai_status (INT) = 乐读派创作进度，status (VARCHAR) = 本地发布状态

-- 1. 新增 leai_status 字段
ALTER TABLE t_ugc_work ADD COLUMN leai_status INT NOT NULL DEFAULT 0
  COMMENT '乐读派创作进度: -1=FAILED, 0=INIT, 1=PENDING, 2=PROCESSING, 3=COMPLETED, 4=CATALOGED, 5=DUBBED';

-- 2. 把现有 status (INT) 值复制到 leai_status
UPDATE t_ugc_work SET leai_status = status;

-- 3. 改 status 字段类型为 VARCHAR
ALTER TABLE t_ugc_work MODIFY COLUMN status VARCHAR(20) NOT NULL DEFAULT 'draft'
  COMMENT '本地发布状态: draft/unpublished/pending_review/published/rejected';

-- 4. 按 leai_status 回填本地 status（保守策略）
UPDATE t_ugc_work SET status = CASE
  WHEN leai_status = -2 THEN 'unpublished'
  WHEN leai_status = -1 THEN 'draft'
  WHEN leai_status = 0  THEN 'draft'
  WHEN leai_status = 1  THEN 'unpublished'
  WHEN leai_status = 2  THEN 'draft'
  WHEN leai_status = 3  THEN 'unpublished'
  WHEN leai_status = 4  THEN 'unpublished'
  WHEN leai_status = 5  THEN 'unpublished'
  ELSE 'draft'
END;

-- 5. 索引
CREATE INDEX idx_ugc_work_status ON t_ugc_work(status);
CREATE INDEX idx_ugc_work_leai_status ON t_ugc_work(leai_status);
