120 lines
6.3 KiB
SQL
120 lines
6.3 KiB
SQL
-- 创建数据库
|
||
CREATE DATABASE IF NOT EXISTS message_archive CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||
USE message_archive;
|
||
CREATE TABLE IF NOT EXISTS message_archive.messages
|
||
(
|
||
id int auto_increment comment '自增主键ID'
|
||
primary key,
|
||
group_id varchar(20) null comment '群ID',
|
||
timestamp varchar(20) not null comment '消息时间戳',
|
||
sender varchar(255) not null comment '发送者微信ID',
|
||
content text null comment '消息内容',
|
||
message_type varchar(50) null comment '消息类型(文本、图片、视频等)',
|
||
attachment_url varchar(512) null comment '附件URL(图片、视频链接)',
|
||
message_id varchar(32) null comment '消息 id',
|
||
message_xml text null comment '消息 xml 部分',
|
||
message_thumb text null comment '视频或图片消息的缩略图路径'
|
||
)
|
||
comment '微信群消息存储表,记录所有群聊消息';
|
||
|
||
CREATE TABLE IF NOT EXISTS message_archive.speech_counts
|
||
(
|
||
id int auto_increment comment '自增主键ID'
|
||
primary key,
|
||
group_id text null comment '群聊ID',
|
||
wx_id text null comment '用户微信ID',
|
||
date text null comment '统计日期(YYYY-MM-DD格式)',
|
||
count int null comment '发言次数',
|
||
constraint speech_counts_group_id_wx_id_date_uindex
|
||
unique (group_id, wx_id, date) using hash
|
||
)
|
||
comment '群成员每日发言统计表';
|
||
|
||
CREATE TABLE IF NOT EXISTS message_archive.t_encyclopedia_active_tasks
|
||
(
|
||
active_task_id int auto_increment comment '任务ID'
|
||
primary key,
|
||
group_id varchar(50) not null comment '群聊ID',
|
||
question varchar(255) not null comment '问题内容',
|
||
answer varchar(100) not null comment '正确答案',
|
||
score int not null comment '答对可获得的分数',
|
||
description text null comment '问题描述或提示',
|
||
holder_id varchar(50) not null comment '出题人ID',
|
||
assigned_at datetime default current_timestamp() null comment '任务分配时间',
|
||
status enum ('pending', 'completed') default 'pending' null comment '任务状态',
|
||
question_id int null comment '问题ID'
|
||
)
|
||
comment '百科答题游戏活跃任务表';
|
||
|
||
create or replace index group_id
|
||
on message_archive.t_encyclopedia_active_tasks (group_id);
|
||
|
||
create or replace index question_id
|
||
on message_archive.t_encyclopedia_active_tasks (question_id);
|
||
|
||
CREATE TABLE IF NOT EXISTS message_archive.t_encyclopedia_groups
|
||
(
|
||
group_id varchar(50) not null comment '群聊ID'
|
||
primary key,
|
||
created_at datetime default current_timestamp() null comment '记录创建时间'
|
||
)
|
||
comment '百科答题游戏群聊表';
|
||
|
||
CREATE TABLE IF NOT EXISTS message_archive.t_encyclopedia_players
|
||
(
|
||
player_id varchar(50) not null comment '玩家ID(微信ID)',
|
||
group_id varchar(50) not null comment '群聊ID',
|
||
player_name varchar(50) not null comment '玩家名称',
|
||
points int default 0 null comment '玩家积分',
|
||
created_at datetime default current_timestamp() null comment '记录创建时间',
|
||
primary key (player_id, group_id)
|
||
)
|
||
comment '百科答题游戏玩家表';
|
||
|
||
CREATE TABLE IF NOT EXISTS message_archive.t_encyclopedia_task_history
|
||
(
|
||
history_id int auto_increment comment '历史记录ID'
|
||
primary key,
|
||
group_id varchar(50) not null comment '群聊ID',
|
||
active_task_id int not null comment '关联的任务ID',
|
||
player_id varchar(50) not null comment '回答者ID',
|
||
answer varchar(100) not null comment '玩家的回答',
|
||
is_correct tinyint(1) default 0 null comment '是否回答正确',
|
||
points_earned int default 0 null comment '获得的积分',
|
||
completed_at datetime default current_timestamp() null comment '完成时间'
|
||
)
|
||
comment '百科答题游戏任务历史表';
|
||
|
||
create or replace index group_id
|
||
on message_archive.t_encyclopedia_task_history (group_id);
|
||
|
||
CREATE TABLE IF NOT EXISTS message_archive.t_sign_record
|
||
(
|
||
id bigint auto_increment comment '自增主键ID'
|
||
primary key,
|
||
wx_id varchar(100) not null comment '用户微信ID',
|
||
group_id varchar(100) not null comment '群聊ID',
|
||
wx_nick_name varchar(100) not null comment '用户昵称',
|
||
points int default 0 null comment '积分数量',
|
||
sign_stat datetime null comment '最近签到时间',
|
||
signin_streak int default 0 null comment '连续签到天数',
|
||
create_time datetime default current_timestamp() null comment '记录创建时间',
|
||
update_time datetime default current_timestamp() null on update current_timestamp() comment '记录更新时间',
|
||
constraint unique_sign
|
||
unique (wx_id, group_id)
|
||
)
|
||
comment '用户群内签到记录表';
|
||
|
||
CREATE TABLE IF NOT EXISTS message_archive.tasks
|
||
(
|
||
task_id int auto_increment comment '任务ID'
|
||
primary key,
|
||
task_description varchar(255) not null comment '任务描述',
|
||
reminder_time time not null comment '提醒时间',
|
||
task_type enum ('single', 'recurring') default 'single' null comment '任务类型:单次或周期性',
|
||
status enum ('pending', 'completed') default 'pending' null comment '任务状态:待办或已完成',
|
||
created_at timestamp default current_timestamp() null comment '创建时间'
|
||
)
|
||
comment '机器人定时任务表';
|
||
|