spark-server/migrations/0009_groups.sql
2026-09-23 17:11:56 +08:00

30 lines
1.9 KiB
SQL
Raw Permalink 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.

-- Group id is a table-local AUTO_INCREMENT 群号. Chat / sync still use Snowflake t_conversations.id.
CREATE TABLE IF NOT EXISTS `t_groups` (
id BIGINT NOT NULL AUTO_INCREMENT COMMENT '群号,表内自增,对外群 ID',
conversation_id BIGINT NOT NULL COMMENT '对应 t_conversations.id(Snowflake),发消息与同步用',
name VARCHAR(32) NOT NULL COMMENT '群名称',
avatar VARCHAR(512) NOT NULL DEFAULT '' COMMENT '群头像对象存储 key,空表示未设置',
owner_id BIGINT NOT NULL COMMENT '群主 user_id',
muted_all TINYINT NOT NULL DEFAULT 0 COMMENT '0=未全员禁言 1=全员禁言(群主/管理员仍可发言)',
member_count INT NOT NULL DEFAULT 0 COMMENT '当前成员数,含群主',
status TINYINT NOT NULL DEFAULT 1 COMMENT '1=正常 2=已解散',
created_at DATETIME(3) NOT NULL COMMENT '创建时间',
updated_at DATETIME(3) NOT NULL COMMENT '资料或成员变更时间',
PRIMARY KEY (id),
UNIQUE KEY uk_conversation (conversation_id),
KEY idx_owner_id (owner_id),
KEY idx_status_updated (status, updated_at)
) COMMENT='群资料。id 是自增群号;会话列表与未读仍按 conversation_id 走 Redis';
CREATE TABLE IF NOT EXISTS t_group_members (
group_id BIGINT NOT NULL COMMENT '群号,t_groups.id',
user_id BIGINT NOT NULL COMMENT '成员 user_id',
role TINYINT NOT NULL DEFAULT 3 COMMENT '1=群主 2=管理员 3=普通成员',
nickname VARCHAR(32) NOT NULL DEFAULT '' COMMENT '群内昵称,空则用用户昵称',
speak_muted TINYINT NOT NULL DEFAULT 0 COMMENT '0=未禁言 1=被单独禁言',
joined_at DATETIME(3) NOT NULL COMMENT '入群时间',
PRIMARY KEY (group_id, user_id),
KEY idx_user_id (user_id)
) COMMENT='群成员与角色。热路径 MemberIDs 可短缓存;免打扰在 t_conversation_members';