zhibo/group_tables.sql

69 lines
3.5 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.

-- 群组系统数据库表
-- 请在服务器数据库中执行此脚本
-- 1. 群组表
CREATE TABLE IF NOT EXISTS `eb_group` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '群组ID',
`group_name` varchar(100) NOT NULL COMMENT '群组名称',
`avatar` varchar(500) DEFAULT NULL COMMENT '群头像',
`description` varchar(500) DEFAULT NULL COMMENT '群描述',
`announcement` varchar(1000) DEFAULT NULL COMMENT '群公告',
`owner_id` int(11) NOT NULL COMMENT '群主用户ID',
`member_count` int(11) NOT NULL DEFAULT 1 COMMENT '成员数量',
`max_members` int(11) NOT NULL DEFAULT 500 COMMENT '最大成员数',
`mute_all` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否全员禁言',
`allow_member_invite` tinyint(1) NOT NULL DEFAULT 1 COMMENT '是否允许成员邀请',
`is_deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否已删除',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`),
KEY `idx_owner_id` (`owner_id`),
KEY `idx_create_time` (`create_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='群组表';
-- 2. 群组成员表
CREATE TABLE IF NOT EXISTS `eb_group_member` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`group_id` bigint(20) NOT NULL COMMENT '群组ID',
`user_id` int(11) NOT NULL COMMENT '用户ID',
`role` tinyint(1) NOT NULL DEFAULT 0 COMMENT '角色0-普通成员 1-管理员 2-群主',
`nickname` varchar(50) DEFAULT NULL COMMENT '群内昵称',
`is_muted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否被禁言',
`is_deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否已退出',
`join_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '加入时间',
`update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_group_user` (`group_id`, `user_id`),
KEY `idx_group_id` (`group_id`),
KEY `idx_user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='群组成员表';
-- 3. 群消息表
CREATE TABLE IF NOT EXISTS `eb_group_message` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '消息ID',
`group_id` bigint(20) NOT NULL COMMENT '群组ID',
`sender_id` int(11) NOT NULL COMMENT '发送者用户ID',
`content` text NOT NULL COMMENT '消息内容',
`message_type` varchar(20) NOT NULL DEFAULT 'text' COMMENT '消息类型text/image/voice/video/file',
`extra` varchar(1000) DEFAULT NULL COMMENT '扩展信息JSON格式',
`is_deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否已删除',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '发送时间',
PRIMARY KEY (`id`),
KEY `idx_group_id` (`group_id`),
KEY `idx_sender_id` (`sender_id`),
KEY `idx_create_time` (`create_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='群消息表';
-- 4. 群消息已读记录表(可选,用于已读回执)
CREATE TABLE IF NOT EXISTS `eb_group_message_read` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`group_id` bigint(20) NOT NULL COMMENT '群组ID',
`user_id` int(11) NOT NULL COMMENT '用户ID',
`last_read_message_id` bigint(20) NOT NULL DEFAULT 0 COMMENT '最后已读消息ID',
`read_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '阅读时间',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_group_user` (`group_id`, `user_id`),
KEY `idx_group_id` (`group_id`),
KEY `idx_user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='群消息已读记录表';