35 lines
2.0 KiB
SQL
35 lines
2.0 KiB
SQL
CREATE TABLE IF NOT EXISTS `la_private_chat_session` (
|
|
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
|
|
`user_a_id` int unsigned NOT NULL DEFAULT 0 COMMENT '较小用户ID',
|
|
`user_b_id` int unsigned NOT NULL DEFAULT 0 COMMENT '较大用户ID',
|
|
`last_message_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT '最后消息ID',
|
|
`last_message_type` varchar(20) NOT NULL DEFAULT 'text' COMMENT '最后消息类型 text/image',
|
|
`last_message_content` varchar(500) NOT NULL DEFAULT '' COMMENT '最后消息内容',
|
|
`last_sender_id` int unsigned NOT NULL DEFAULT 0 COMMENT '最后发送者',
|
|
`user_a_unread` int unsigned NOT NULL DEFAULT 0 COMMENT '用户A未读数',
|
|
`user_b_unread` int unsigned NOT NULL DEFAULT 0 COMMENT '用户B未读数',
|
|
`last_active_time` int unsigned NOT NULL DEFAULT 0 COMMENT '最后活跃时间',
|
|
`create_time` int unsigned NOT NULL DEFAULT 0,
|
|
`update_time` int unsigned NOT NULL DEFAULT 0,
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `uk_pair` (`user_a_id`, `user_b_id`),
|
|
KEY `idx_user_a_active` (`user_a_id`, `last_active_time`),
|
|
KEY `idx_user_b_active` (`user_b_id`, `last_active_time`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户私聊会话表';
|
|
|
|
CREATE TABLE IF NOT EXISTS `la_private_chat_message` (
|
|
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
|
|
`session_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT '会话ID',
|
|
`sender_id` int unsigned NOT NULL DEFAULT 0 COMMENT '发送者',
|
|
`receiver_id` int unsigned NOT NULL DEFAULT 0 COMMENT '接收者',
|
|
`message_type` varchar(20) NOT NULL DEFAULT 'text' COMMENT '消息类型 text/image',
|
|
`content` text NULL COMMENT '消息内容',
|
|
`read_time` int unsigned NOT NULL DEFAULT 0 COMMENT '接收者阅读时间',
|
|
`create_time` int unsigned NOT NULL DEFAULT 0,
|
|
`update_time` int unsigned NOT NULL DEFAULT 0,
|
|
PRIMARY KEY (`id`),
|
|
KEY `idx_session_id` (`session_id`, `id`),
|
|
KEY `idx_receiver_read` (`receiver_id`, `read_time`),
|
|
KEY `idx_sender_time` (`sender_id`, `create_time`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户私聊消息表';
|