zhibo/Zhibo/zhibo-h/sql/create_conversation_tables.sql
2025-12-26 15:16:40 +08:00

50 lines
2.9 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 私聊会话表
CREATE TABLE IF NOT EXISTS `eb_conversation` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '会话ID',
`user1_id` int(11) NOT NULL COMMENT '用户1的ID',
`user2_id` int(11) NOT NULL COMMENT '用户2的ID',
`last_message` varchar(500) DEFAULT '' COMMENT '最后一条消息内容',
`last_message_time` datetime DEFAULT NULL COMMENT '最后一条消息时间',
`user1_unread_count` int(11) DEFAULT 0 COMMENT '用户1的未读数量',
`user2_unread_count` int(11) DEFAULT 0 COMMENT '用户2的未读数量',
`user1_deleted` tinyint(1) DEFAULT 0 COMMENT '用户1是否删除会话',
`user2_deleted` tinyint(1) DEFAULT 0 COMMENT '用户2是否删除会话',
`user1_muted` tinyint(1) DEFAULT 0 COMMENT '用户1是否静音',
`user2_muted` tinyint(1) DEFAULT 0 COMMENT '用户2是否静音',
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`),
KEY `idx_user1_id` (`user1_id`),
KEY `idx_user2_id` (`user2_id`),
KEY `idx_last_message_time` (`last_message_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='私聊会话表';
-- 私信消息表
CREATE TABLE IF NOT EXISTS `eb_private_message` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '消息ID',
`conversation_id` bigint(20) NOT NULL COMMENT '会话ID',
`sender_id` int(11) NOT NULL COMMENT '发送者用户ID',
`receiver_id` int(11) NOT NULL COMMENT '接收者用户ID',
`content` text COMMENT '消息内容',
`message_type` varchar(20) DEFAULT 'text' COMMENT '消息类型: text, image, file',
`status` varchar(20) DEFAULT 'sent' COMMENT '消息状态: sending, sent, read',
`sender_deleted` tinyint(1) DEFAULT 0 COMMENT '发送者是否删除',
`receiver_deleted` tinyint(1) DEFAULT 0 COMMENT '接收者是否删除',
`is_recalled` tinyint(1) DEFAULT 0 COMMENT '是否已撤回',
`recall_time` datetime DEFAULT NULL COMMENT '撤回时间',
`reply_to_message_id` bigint(20) DEFAULT NULL COMMENT '引用的消息ID回复功能',
`reply_to_content` varchar(200) DEFAULT NULL COMMENT '引用的消息内容预览(冗余存储)',
`reply_to_sender_id` int(11) DEFAULT NULL COMMENT '引用的消息发送者ID',
`reply_to_sender_name` varchar(50) DEFAULT NULL COMMENT '引用的消息发送者昵称(冗余存储)',
`reply_to_message_type` varchar(20) DEFAULT NULL COMMENT '引用的消息类型',
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`read_time` datetime DEFAULT NULL COMMENT '已读时间',
PRIMARY KEY (`id`),
KEY `idx_conversation_id` (`conversation_id`),
KEY `idx_sender_id` (`sender_id`),
KEY `idx_receiver_id` (`receiver_id`),
KEY `idx_create_time` (`create_time`),
KEY `idx_is_recalled` (`is_recalled`),
KEY `idx_reply_to_message_id` (`reply_to_message_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='私信消息表';