zhibo/fix_records_v2.sql

50 lines
2.1 KiB
MySQL
Raw Normal View History

-- =====================================================
-- 修复"我的记录"不显示数据问题 - V2
-- =====================================================
-- 1. 先查看 eb_user 表结构,确认列名
DESC eb_user;
-- 2. 查询用户(使用 uid 作为主键)
SELECT uid, nickname, phone, avatar FROM eb_user WHERE nickname LIKE '%道玄%';
-- 3. 检查观看历史表是否存在
SHOW TABLES LIKE 'eb_view_history';
-- 4. 如果表不存在,创建它
CREATE TABLE IF NOT EXISTS `eb_view_history` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`user_id` int(11) NOT NULL COMMENT '用户ID',
`target_type` varchar(20) NOT NULL COMMENT '目标类型room-直播间, work-作品, profile-用户主页',
`target_id` varchar(50) NOT NULL COMMENT '目标ID',
`target_title` varchar(255) DEFAULT NULL COMMENT '目标标题',
`view_duration` int(11) DEFAULT 0 COMMENT '观看时长(秒)',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '查看时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`),
KEY `idx_user_id` (`user_id`),
KEY `idx_target` (`target_type`, `target_id`),
KEY `idx_create_time` (`create_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='查看历史记录表';
-- 5. 查看现有观看历史数据
SELECT * FROM eb_view_history ORDER BY update_time DESC LIMIT 20;
-- 6. 查看直播间列表
SELECT id, title, streamer_id FROM eb_live_room LIMIT 10;
-- =====================================================
-- 为用户121添加测试数据假设道玄的uid是121
-- 如果不是121请替换为实际的uid值
-- =====================================================
-- 插入观看历史
INSERT INTO eb_view_history (user_id, target_type, target_id, target_title, view_duration, create_time, update_time)
VALUES
(121, 'room', '1', '欢乐游戏直播', 1800, NOW(), NOW()),
(121, 'room', '2', '音乐分享会', 2400, NOW(), NOW()),
(121, 'room', '8', '火影忍者', 3600, NOW(), NOW());
-- 验证插入结果
SELECT * FROM eb_view_history WHERE user_id = 121;