-- 为 user_day_statistics 表添加所有字段的完整迁移脚本
-- 执行日期: 2026-01-28
-- 
-- 说明：
-- 1. 如果字段已存在，会报错，需要先检查或手动删除重复的 ADD COLUMN 语句
-- 2. 四个统计字段（cover_click_rate, avg_watch_duration, total_watch_duration, completion_rate）使用字符串类型

USE media_manager;

-- 添加基础统计字段
ALTER TABLE user_day_statistics
ADD COLUMN IF NOT EXISTS play_count INT DEFAULT 0 COMMENT '播放数' AFTER works_count,
ADD COLUMN IF NOT EXISTS comment_count INT DEFAULT 0 COMMENT '评论数' AFTER play_count,
ADD COLUMN IF NOT EXISTS fans_increase INT DEFAULT 0 COMMENT '涨粉数' AFTER comment_count,
ADD COLUMN IF NOT EXISTS like_count INT DEFAULT 0 COMMENT '点赞数' AFTER fans_increase;

-- 添加字符串格式的统计字段
ALTER TABLE user_day_statistics
ADD COLUMN IF NOT EXISTS cover_click_rate VARCHAR(50) DEFAULT '0' COMMENT '封面点击率' AFTER like_count,
ADD COLUMN IF NOT EXISTS avg_watch_duration VARCHAR(50) DEFAULT '0' COMMENT '平均观看时长（秒）' AFTER cover_click_rate,
ADD COLUMN IF NOT EXISTS total_watch_duration VARCHAR(50) DEFAULT '0' COMMENT '观看总时长（秒）' AFTER avg_watch_duration,
ADD COLUMN IF NOT EXISTS completion_rate VARCHAR(50) DEFAULT '0' COMMENT '视频完播率' AFTER total_watch_duration;
