去除无效sql

This commit is contained in:
liuwei
2026-05-07 13:38:26 +08:00
parent 4515b605b9
commit 81ea198aa2
8 changed files with 544 additions and 358 deletions

View File

@@ -27,9 +27,6 @@ ABOT_EMAIL_SENDER=
ABOT_EMAIL_PASSWORD=
ABOT_EMAIL_ALERT_RECIPIENT=
ABOT_GLANCES_HOST=127.0.0.1
ABOT_GLANCES_PORT=61208
ABOT_WX_ADMIN=admin
WECHAT_SERVER_URL=http://127.0.0.1:8059/

View File

@@ -1,33 +1,4 @@
-- 创建数据库
CREATE DATABASE IF NOT EXISTS message_archive CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
USE message_archive;
create or replace table message_archive.forum_posts
(
id int auto_increment
primary key,
tid varchar(50) not null comment '帖子ID',
fid int not null comment '板块ID',
category_name varchar(50) null comment '板块名称',
designation varchar(100) null comment '番号',
actress varchar(100) null comment '出演女优',
title varchar(255) not null comment '标题',
magnet_link text null comment '磁力链接',
cover_image varchar(500) null comment '封面图URL',
post_url varchar(255) not null comment '帖子链接',
publish_date varchar(20) null comment '发布时间',
created_at timestamp default current_timestamp() null,
updated_at timestamp default current_timestamp() null on update current_timestamp(),
constraint tid
unique (tid)
);
create or replace index forum_posts_designation_index
on message_archive.forum_posts (designation);
create or replace index idx_actress
on message_archive.forum_posts (actress);
create or replace table message_archive.messages
CREATE TABLE IF NOT EXISTS messages
(
id int auto_increment comment '自增主键ID'
primary key,
@@ -46,90 +17,31 @@ create or replace table message_archive.messages
)
comment '微信群消息存储表,记录所有群聊消息';
create or replace index idx_date_timestamp
on message_archive.messages (timestamp);
CREATE INDEX IF NOT EXISTS idx_date_timestamp
on messages (timestamp);
create or replace index idx_group_timestamp
on message_archive.messages (group_id, timestamp);
CREATE INDEX IF NOT EXISTS idx_group_sender_timestamp
on messages (group_id, sender, timestamp);
create or replace index idx_message_sender
on message_archive.messages (sender);
CREATE INDEX IF NOT EXISTS idx_group_timestamp
on messages (group_id, timestamp);
create or replace index idx_message_type
on message_archive.messages (message_type);
CREATE INDEX IF NOT EXISTS idx_group_type_timestamp
on messages (group_id, message_type, timestamp);
create or replace index messages_message_id_index
on message_archive.messages (message_id);
CREATE INDEX IF NOT EXISTS idx_media_pending_lookup
on messages (message_type, image_path, timestamp, group_id);
create or replace table message_archive.t_emoji_assets
(
md5 varchar(64) not null comment '表情MD5'
primary key,
total_length int not null default 0 comment '表情总长度',
semantic_text varchar(255) null comment '主语义文本',
semantic_aliases longtext null comment '语义别名列表(JSON数组)',
semantic_source varchar(64) null comment '语义来源字段如desc/emojiattr',
preview_url varchar(255) null comment '本地预览图路径',
sample_message_id varchar(32) null comment '样例消息ID',
sample_group_id varchar(100) null comment '样例群ID',
sample_sender varchar(100) null comment '样例发送者',
first_seen_at datetime default current_timestamp() null comment '首次看到时间',
last_seen_at datetime default current_timestamp() null on update current_timestamp() comment '最近看到时间',
created_at datetime default current_timestamp() null comment '创建时间',
updated_at datetime default current_timestamp() null on update current_timestamp() comment '更新时间'
)
comment '表情语义资产表';
CREATE INDEX IF NOT EXISTS idx_message_sender
on messages (sender);
create or replace index idx_emoji_last_seen
on message_archive.t_emoji_assets (last_seen_at);
CREATE INDEX IF NOT EXISTS idx_message_type
on messages (message_type);
create or replace index idx_emoji_preview
on message_archive.t_emoji_assets (preview_url);
CREATE INDEX IF NOT EXISTS messages_message_id_index
on messages (message_id);
create or replace table message_archive.t_message_mentions
(
id bigint auto_increment
primary key,
message_id varchar(32) not null comment '原始消息ID',
group_id varchar(100) not null comment '群ID',
sender_id varchar(100) not null comment '发送者ID@发起人)',
mentioned_user_id varchar(100) not null comment '被@用户ID',
stat_date date not null comment '统计日期',
msg_time datetime not null comment '消息时间',
create_time datetime default current_timestamp() null comment '创建时间',
constraint uk_message_sender_mentioned
unique (message_id, sender_id, mentioned_user_id)
)
comment '消息@关系明细表';
create or replace index idx_group_date
on message_archive.t_message_mentions (group_id, stat_date);
create or replace index idx_mentioned_group_date
on message_archive.t_message_mentions (mentioned_user_id, group_id, stat_date);
create or replace table message_archive.t_social_edges_daily
(
id bigint auto_increment
primary key,
stat_date date not null comment '统计日期',
group_id varchar(100) not null comment '群ID',
from_user_id varchar(100) not null comment '互动发起方',
to_user_id varchar(100) not null comment '互动接收方',
mention_count int default 0 not null comment '@次数',
reply_count int default 0 not null comment '回复次数(预留)',
interaction_score decimal(10, 2) default 0.00 not null comment '互动强度分(可用于关系网权重)',
create_time datetime default current_timestamp() null comment '创建时间',
update_time datetime default current_timestamp() null on update current_timestamp() comment '更新时间',
constraint uk_day_group_edge
unique (stat_date, group_id, from_user_id, to_user_id)
)
comment '社交关系日边表(用于关系网和搭子榜)';
create or replace index idx_group_day_score
on message_archive.t_social_edges_daily (group_id, stat_date, interaction_score);
create or replace table message_archive.speech_counts
CREATE TABLE IF NOT EXISTS speech_counts
(
id int auto_increment comment '自增主键ID'
primary key,
@@ -142,7 +54,24 @@ create or replace table message_archive.speech_counts
)
comment '群成员每日发言统计表';
create or replace table message_archive.t_chatroom_member
CREATE TABLE IF NOT EXISTS t_admin_accounts
(
id bigint auto_increment
primary key,
username varchar(64) not null comment '登录用户名',
password_hash varchar(255) not null comment '口令哈希',
display_name varchar(64) null comment '展示名称',
status tinyint default 1 not null comment '状态1启用0禁用',
last_login_at datetime null comment '最近登录时间',
last_login_ip varchar(64) null comment '最近登录IP',
create_time datetime default current_timestamp() null comment '创建时间',
update_time datetime default current_timestamp() null on update current_timestamp() comment '更新时间',
constraint uk_admin_username
unique (username)
)
comment '后台管理员账号表';
CREATE TABLE IF NOT EXISTS t_chatroom_member
(
id int auto_increment
primary key,
@@ -177,7 +106,7 @@ create or replace table message_archive.t_chatroom_member
)
comment '微信群成员信息表';
create or replace table message_archive.t_chatrooms
CREATE TABLE IF NOT EXISTS t_chatrooms
(
id int auto_increment
primary key,
@@ -191,17 +120,41 @@ create or replace table message_archive.t_chatrooms
remark_quan_pin varchar(256) null comment '备注全拼',
chat_room_notify tinyint null comment '群通知',
chat_room_owner varchar(64) null comment '群主微信ID',
chat_room_announcement text null comment '群公告内容',
small_head_img_url text null comment '群头像URL',
member_list text null comment '成员列表(JSON)',
create_time datetime default current_timestamp() not null comment '创建时间',
update_time datetime default current_timestamp() not null on update current_timestamp() comment '更新时间',
chat_room_announcement text null comment '群公告内容',
constraint idx_chatroom_id
unique (chatroom_id)
)
comment '微信群信息表';
create or replace table message_archive.t_encyclopedia_active_tasks
CREATE TABLE IF NOT EXISTS t_emoji_assets
(
md5 varchar(64) not null
primary key,
total_length int default 0 not null,
semantic_text varchar(255) default '' null comment '主语义文本',
semantic_aliases longtext null comment '语义别名列表(JSON数组)',
semantic_source varchar(64) default '' null comment '语义来源字段,如 desc/emojiattr',
preview_url varchar(255) default '' null comment '本地预览图路径',
sample_message_id varchar(32) default '' null comment '示例消息ID',
sample_group_id varchar(100) default '' null comment '示例群ID',
sample_sender varchar(100) default '' null comment '示例发送者',
first_seen_at datetime default current_timestamp() null,
last_seen_at datetime default current_timestamp() null on update current_timestamp(),
created_at datetime default current_timestamp() null,
updated_at datetime default current_timestamp() null on update current_timestamp()
);
CREATE INDEX IF NOT EXISTS idx_emoji_last_seen
on t_emoji_assets (last_seen_at);
CREATE INDEX IF NOT EXISTS idx_emoji_preview
on t_emoji_assets (preview_url);
CREATE TABLE IF NOT EXISTS t_encyclopedia_active_tasks
(
active_task_id int auto_increment comment '任务ID'
primary key,
@@ -217,13 +170,13 @@ create or replace table message_archive.t_encyclopedia_active_tasks
)
comment '百科答题游戏活跃任务表';
create or replace index group_id
on message_archive.t_encyclopedia_active_tasks (group_id);
CREATE INDEX IF NOT EXISTS group_id
on t_encyclopedia_active_tasks (group_id);
create or replace index question_id
on message_archive.t_encyclopedia_active_tasks (question_id);
CREATE INDEX IF NOT EXISTS question_id
on t_encyclopedia_active_tasks (question_id);
create or replace table message_archive.t_encyclopedia_groups
CREATE TABLE IF NOT EXISTS t_encyclopedia_groups
(
group_id varchar(50) not null comment '群聊ID'
primary key,
@@ -231,7 +184,7 @@ create or replace table message_archive.t_encyclopedia_groups
)
comment '百科答题游戏群聊表';
create or replace table message_archive.t_encyclopedia_players
CREATE TABLE IF NOT EXISTS t_encyclopedia_players
(
player_id varchar(50) not null comment '玩家ID微信ID',
group_id varchar(50) not null comment '群聊ID',
@@ -242,7 +195,7 @@ create or replace table message_archive.t_encyclopedia_players
)
comment '百科答题游戏玩家表';
create or replace table message_archive.t_encyclopedia_task_history
CREATE TABLE IF NOT EXISTS t_encyclopedia_task_history
(
history_id int auto_increment comment '历史记录ID'
primary key,
@@ -256,10 +209,10 @@ create or replace table message_archive.t_encyclopedia_task_history
)
comment '百科答题游戏任务历史表';
create or replace index group_id
on message_archive.t_encyclopedia_task_history (group_id);
CREATE INDEX IF NOT EXISTS group_id
on t_encyclopedia_task_history (group_id);
create or replace table message_archive.t_error_logs
CREATE TABLE IF NOT EXISTS t_error_logs
(
id bigint auto_increment
primary key,
@@ -273,37 +226,42 @@ create or replace table message_archive.t_error_logs
)
comment '错误日志表';
create or replace index idx_created_at
on message_archive.t_error_logs (created_at);
CREATE INDEX IF NOT EXISTS idx_created_at
on t_error_logs (created_at);
create or replace index idx_plugin_name
on message_archive.t_error_logs (plugin_name);
CREATE INDEX IF NOT EXISTS idx_plugin_name
on t_error_logs (plugin_name);
create or replace table message_archive.t_group_stats
CREATE TABLE IF NOT EXISTS t_fun_command_rule
(
id bigint auto_increment
primary key,
group_id varchar(50) not null comment '群组ID',
plugin_name varchar(50) not null comment '插件名称',
command varchar(50) not null comment '触发的命令',
total_calls int default 0 not null comment '总调用次数',
success_calls int default 0 not null comment '成功调用次数',
failed_calls int default 0 not null comment '失败调用次数',
unique_users int default 0 not null comment '唯一用户数',
first_used_at datetime not null comment '首次使用时间',
last_used_at datetime not null comment '最后使用时间',
constraint uk_group_plugin_command
unique (group_id, plugin_name, command)
)
comment '群组使用统计表';
rule_name varchar(128) not null,
scope_type varchar(20) default 'global' not null,
scope_id varchar(100) default '' not null,
trigger_type varchar(20) default 'exact' not null,
trigger_text varchar(500) default '' not null,
event_key varchar(64) default '' not null,
responses_json longtext collate utf8mb4_bin not null
check (json_valid(`responses_json`)),
priority int default 100 not null,
cooldown_seconds int default 0 not null,
enabled tinyint(1) default 1 not null,
updated_by varchar(100) default 'system' not null,
created_at datetime default current_timestamp() null,
updated_at datetime default current_timestamp() null on update current_timestamp()
);
create or replace index idx_group_id
on message_archive.t_group_stats (group_id);
CREATE INDEX IF NOT EXISTS idx_event_key
on t_fun_command_rule (event_key);
create or replace index idx_last_used_at
on message_archive.t_group_stats (last_used_at);
CREATE INDEX IF NOT EXISTS idx_scope_enabled_priority
on t_fun_command_rule (scope_type, scope_id, enabled, priority);
create or replace table message_archive.t_group_command_user_stats
CREATE INDEX IF NOT EXISTS idx_trigger_type
on t_fun_command_rule (trigger_type);
CREATE TABLE IF NOT EXISTS t_group_command_user_stats
(
id bigint auto_increment
primary key,
@@ -318,13 +276,262 @@ create or replace table message_archive.t_group_command_user_stats
)
comment '群命令用户去重追踪表';
create or replace index idx_group_plugin_command
on message_archive.t_group_command_user_stats (group_id, plugin_name, command);
CREATE INDEX IF NOT EXISTS idx_group_plugin_command
on t_group_command_user_stats (group_id, plugin_name, command);
create or replace index idx_group_command_user_last_used
on message_archive.t_group_command_user_stats (last_used_at);
CREATE INDEX IF NOT EXISTS idx_last_used_at
on t_group_command_user_stats (last_used_at);
create or replace table message_archive.t_plugin_point_config
CREATE TABLE IF NOT EXISTS t_group_plugin_config
(
id bigint auto_increment
primary key,
group_id varchar(100) not null,
plugin_name varchar(128) not null,
config_key varchar(128) default 'default' not null,
config_json longtext collate utf8mb4_bin not null
check (json_valid(`config_json`)),
enabled tinyint(1) default 1 not null,
version int default 1 not null,
updated_by varchar(100) default 'system' not null,
created_at datetime default current_timestamp() null,
updated_at datetime default current_timestamp() null on update current_timestamp(),
constraint uk_group_plugin_key
unique (group_id, plugin_name, config_key)
);
CREATE INDEX IF NOT EXISTS idx_group_plugin
on t_group_plugin_config (group_id, plugin_name);
CREATE INDEX IF NOT EXISTS idx_plugin_name
on t_group_plugin_config (plugin_name);
CREATE TABLE IF NOT EXISTS t_group_profile_snapshot
(
id int auto_increment
primary key,
chatroom_id varchar(64) not null comment '群聊ID',
group_name varchar(128) default '' null comment '群名称',
profile_json longtext null comment '群画像快照JSON',
source_summary_latest_at datetime null comment '构建时参考的最近群总结更新时间',
source_message_latest_at datetime null comment '构建时参考的最近群消息时间',
source_summary_count int default 0 not null comment '构建时参考的群总结条数',
source_message_sample_count int default 0 not null comment '构建时参考的消息样本数',
last_generated_at datetime default current_timestamp() not null comment '最后一次生成时间',
create_time datetime default current_timestamp() not null comment '创建时间',
update_time datetime default current_timestamp() not null on update current_timestamp() comment '更新时间',
constraint idx_group_profile_snapshot
unique (chatroom_id)
)
comment '群画像快照表';
CREATE INDEX IF NOT EXISTS idx_group_profile_generated_at
on t_group_profile_snapshot (last_generated_at);
CREATE TABLE IF NOT EXISTS t_group_stats
(
id bigint auto_increment
primary key,
group_id varchar(50) not null comment '群组ID',
plugin_name varchar(50) not null comment '插件名称',
command varchar(512) not null comment '触发的命令',
total_calls int default 0 not null comment '总调用次数',
success_calls int default 0 not null comment '成功调用次数',
failed_calls int default 0 not null comment '失败调用次数',
unique_users int default 0 not null comment '唯一用户数',
first_used_at datetime not null comment '首次使用时间',
last_used_at datetime not null comment '最后使用时间',
constraint uk_group_plugin_command
unique (group_id, plugin_name, command)
)
comment '群组使用统计表';
CREATE INDEX IF NOT EXISTS idx_group_id
on t_group_stats (group_id);
CREATE INDEX IF NOT EXISTS idx_last_used_at
on t_group_stats (last_used_at);
CREATE TABLE IF NOT EXISTS t_llm_backends
(
name varchar(128) not null
primary key,
config_json longtext collate utf8mb4_bin not null
check (json_valid(`config_json`)),
enabled tinyint(1) default 1 not null,
created_at datetime default current_timestamp() null,
updated_at datetime default current_timestamp() null on update current_timestamp()
);
CREATE TABLE IF NOT EXISTS t_llm_catalog_meta
(
meta_key varchar(64) not null
primary key,
meta_value varchar(255) not null,
updated_at datetime default current_timestamp() null on update current_timestamp()
);
CREATE TABLE IF NOT EXISTS t_llm_dify_apps
(
name varchar(128) not null
primary key,
provider_template varchar(128) not null,
app_key varchar(255) not null,
workflow_output_key varchar(128) default 'text' null,
config_json longtext collate utf8mb4_bin not null
check (json_valid(`config_json`)),
enabled tinyint(1) default 1 not null,
created_at datetime default current_timestamp() null,
updated_at datetime default current_timestamp() null on update current_timestamp()
);
CREATE INDEX IF NOT EXISTS idx_provider_template
on t_llm_dify_apps (provider_template);
CREATE TABLE IF NOT EXISTS t_llm_provider_templates
(
name varchar(128) not null
primary key,
provider_type varchar(64) not null,
config_json longtext collate utf8mb4_bin not null
check (json_valid(`config_json`)),
enabled tinyint(1) default 1 not null,
created_at datetime default current_timestamp() null,
updated_at datetime default current_timestamp() null on update current_timestamp()
);
CREATE TABLE IF NOT EXISTS t_llm_scenes
(
name varchar(128) not null
primary key,
target_type varchar(32) not null,
target_ref varchar(128) not null,
enabled tinyint(1) default 1 not null,
created_at datetime default current_timestamp() null,
updated_at datetime default current_timestamp() null on update current_timestamp()
);
CREATE INDEX IF NOT EXISTS idx_target
on t_llm_scenes (target_type, target_ref);
CREATE TABLE IF NOT EXISTS t_member_context
(
id int auto_increment
primary key,
chatroom_id varchar(64) not null comment '群聊ID',
wxid varchar(64) not null comment '成员微信ID',
display_name varchar(128) null comment '成员展示名',
activity_level varchar(32) null comment '活跃等级',
message_pattern varchar(255) null comment '发言模式',
response_style_hint varchar(255) null comment '回复建议',
topics_of_interest text null comment '兴趣主题(JSON)',
recent_focus text null comment '近期关注(JSON)',
summary_text text null comment '交互摘要',
confidence decimal(4, 2) default 0.00 null comment '摘要置信度',
source_message_count int default 0 null comment '样本消息数',
source_days int default 30 null comment '采样天数',
meta_json longtext null comment '附加元数据(JSON)',
last_profiled_at datetime default current_timestamp() not null comment '最后生成时间',
create_time datetime default current_timestamp() not null comment '创建时间',
update_time datetime default current_timestamp() not null on update current_timestamp() comment '更新时间',
interaction_style varchar(255) null comment '互动风格',
constraint idx_member_context
unique (chatroom_id, wxid)
)
comment '群成员交互摘要表';
CREATE TABLE IF NOT EXISTS t_member_digest
(
id int auto_increment
primary key,
chatroom_id varchar(64) not null comment '群聊ID',
wxid varchar(64) not null comment '成员微信ID',
digest_type varchar(16) not null comment '摘要类型 daily|weekly|monthly',
period_key varchar(32) not null comment '周期主键',
period_start datetime null comment '周期开始时间',
period_end datetime null comment '周期结束时间',
display_name varchar(128) null comment '成员展示名',
source_count int default 0 null comment '源数据条数',
summary_text text null comment '摘要说明',
structured_json longtext null comment '结构化摘要JSON',
meta_json longtext null comment '附加元数据JSON',
last_generated_at datetime default current_timestamp() not null comment '最后生成时间',
create_time datetime default current_timestamp() not null comment '创建时间',
update_time datetime default current_timestamp() not null on update current_timestamp() comment '更新时间',
constraint idx_member_digest
unique (chatroom_id, wxid, digest_type, period_key)
)
comment '成员分层摘要表';
CREATE INDEX IF NOT EXISTS idx_digest_lookup
on t_member_digest (chatroom_id, wxid, digest_type, period_end);
CREATE TABLE IF NOT EXISTS t_member_digest_group_state
(
id int auto_increment
primary key,
chatroom_id varchar(64) not null comment '群聊ID',
bootstrap_status varchar(16) default 'pending' not null comment '初始化状态 pending|done|empty',
last_bootstrap_at datetime null comment '最近一次初始化尝试时间',
bootstrap_days int default 0 not null comment '最近一次初始化窗口天数',
built_daily_count int default 0 not null comment '最近一次初始化生成的日摘要数量',
touched_member_count int default 0 not null comment '最近一次初始化触达的成员数量',
extra_json longtext null comment '附加状态信息',
create_time datetime default current_timestamp() not null comment '创建时间',
update_time datetime default current_timestamp() not null on update current_timestamp() comment '更新时间',
constraint idx_digest_group_state
unique (chatroom_id)
)
comment '成员分层摘要群级状态表';
CREATE TABLE IF NOT EXISTS t_message_mentions
(
id bigint auto_increment
primary key,
message_id varchar(32) not null comment '原始消息ID',
group_id varchar(100) not null comment '群ID',
sender_id varchar(100) not null comment '发送者ID@发起人)',
mentioned_user_id varchar(100) not null comment '被@用户ID',
stat_date date not null comment '统计日期',
msg_time datetime not null comment '消息时间',
create_time datetime default current_timestamp() null comment '创建时间',
constraint uk_message_sender_mentioned
unique (message_id, sender_id, mentioned_user_id)
)
comment '消息@关系明细表';
CREATE INDEX IF NOT EXISTS idx_group_date
on t_message_mentions (group_id, stat_date);
CREATE INDEX IF NOT EXISTS idx_mentioned_group_date
on t_message_mentions (mentioned_user_id, group_id, stat_date);
CREATE TABLE IF NOT EXISTS t_message_summary
(
id int auto_increment
primary key,
chatroom_id varchar(64) not null comment '群聊ID',
group_name varchar(128) default '' null comment '群名称',
summary_type varchar(16) not null comment '总结类型 daily|manual',
period_key varchar(32) not null comment '周期主键,如 2026-04-01',
period_start datetime null comment '总结周期开始时间',
period_end datetime null comment '总结周期结束时间',
source_message_count int default 0 not null comment '源消息数量',
summary_text longtext null comment '总结文本',
image_path varchar(255) null comment '总结图片路径',
meta_json longtext null comment '附加元数据JSON',
last_generated_at datetime default current_timestamp() not null comment '最后生成时间',
create_time datetime default current_timestamp() not null comment '创建时间',
update_time datetime default current_timestamp() not null on update current_timestamp() comment '更新时间',
constraint idx_message_summary
unique (chatroom_id, summary_type, period_key)
)
comment '群消息总结表';
CREATE INDEX IF NOT EXISTS idx_message_summary_lookup
on t_message_summary (chatroom_id, period_end);
CREATE TABLE IF NOT EXISTS t_plugin_point_config
(
id int auto_increment
primary key,
@@ -336,12 +543,50 @@ create or replace table message_archive.t_plugin_point_config
unique (plugin_name)
);
create or replace table message_archive.t_plugin_stats
CREATE TABLE IF NOT EXISTS t_plugin_schedule_logs
(
id bigint auto_increment
primary key,
schedule_id bigint not null,
triggered_at datetime default current_timestamp() null,
status varchar(32) not null,
summary varchar(255) default '' null,
detail_json longtext collate utf8mb4_bin null
check (json_valid(`detail_json`))
);
CREATE INDEX IF NOT EXISTS idx_schedule_time
on t_plugin_schedule_logs (schedule_id, triggered_at);
CREATE TABLE IF NOT EXISTS t_plugin_schedules
(
id bigint auto_increment
primary key,
plugin_name varchar(128) not null,
action_key varchar(64) not null,
action_name varchar(128) not null,
description varchar(255) default '' null,
trigger_type varchar(64) not null,
trigger_config longtext collate utf8mb4_bin not null
check (json_valid(`trigger_config`)),
target_scope varchar(64) default 'all_enabled_groups' not null,
target_config longtext collate utf8mb4_bin null
check (json_valid(`target_config`)),
payload longtext collate utf8mb4_bin null
check (json_valid(`payload`)),
enabled tinyint(1) default 0 not null,
created_at datetime default current_timestamp() null,
updated_at datetime default current_timestamp() null on update current_timestamp(),
constraint uk_plugin_action
unique (plugin_name, action_key)
);
CREATE TABLE IF NOT EXISTS t_plugin_stats
(
id bigint auto_increment
primary key,
plugin_name varchar(50) not null comment '插件名称',
command varchar(50) not null comment '触发的命令',
command varchar(512) not null comment '触发的命令',
stat_date date not null comment '统计日期',
total_calls int default 0 not null comment '总调用次数',
success_calls int default 0 not null comment '成功调用次数',
@@ -356,10 +601,10 @@ create or replace table message_archive.t_plugin_stats
)
comment '插件统计汇总表';
create or replace index idx_stat_date
on message_archive.t_plugin_stats (stat_date);
CREATE INDEX IF NOT EXISTS idx_stat_date
on t_plugin_stats (stat_date);
create or replace table message_archive.t_point_transactions
CREATE TABLE IF NOT EXISTS t_point_transactions
(
id int auto_increment
primary key,
@@ -372,7 +617,7 @@ create or replace table message_archive.t_point_transactions
created_at timestamp default current_timestamp() null
);
create or replace table message_archive.t_prison_records
CREATE TABLE IF NOT EXISTS t_prison_records
(
id int auto_increment
primary key,
@@ -387,7 +632,7 @@ create or replace table message_archive.t_prison_records
created_at timestamp default current_timestamp() null
);
create or replace table message_archive.t_push_feedback
CREATE TABLE IF NOT EXISTS t_push_feedback
(
feedback_id varchar(36) not null
primary key,
@@ -397,7 +642,7 @@ create or replace table message_archive.t_push_feedback
timestamp datetime default current_timestamp() null
);
create or replace table message_archive.t_push_previews
CREATE TABLE IF NOT EXISTS t_push_previews
(
preview_id varchar(36) not null
primary key,
@@ -412,7 +657,7 @@ create or replace table message_archive.t_push_previews
created_at datetime default current_timestamp() null
);
create or replace table message_archive.t_push_task_logs
CREATE TABLE IF NOT EXISTS t_push_task_logs
(
log_id varchar(36) not null
primary key,
@@ -424,7 +669,7 @@ create or replace table message_archive.t_push_task_logs
timestamp datetime default current_timestamp() null
);
create or replace table message_archive.t_push_tasks
CREATE TABLE IF NOT EXISTS t_push_tasks
(
task_id varchar(36) not null
primary key,
@@ -456,7 +701,7 @@ create or replace table message_archive.t_push_tasks
updated_at datetime default current_timestamp() null on update current_timestamp()
);
create or replace table message_archive.t_sign_history
CREATE TABLE IF NOT EXISTS t_sign_history
(
id bigint auto_increment comment '历史记录ID'
primary key,
@@ -471,13 +716,13 @@ create or replace table message_archive.t_sign_history
)
comment '用户签到历史记录表';
create or replace index idx_sign_date
on message_archive.t_sign_history (sign_date);
CREATE INDEX IF NOT EXISTS idx_sign_date
on t_sign_history (sign_date);
create or replace index idx_user_group
on message_archive.t_sign_history (wx_id, group_id);
CREATE INDEX IF NOT EXISTS idx_user_group
on t_sign_history (wx_id, group_id);
create or replace table message_archive.t_sign_record
CREATE TABLE IF NOT EXISTS t_sign_record
(
id bigint auto_increment comment '自增主键ID'
primary key,
@@ -499,7 +744,58 @@ create or replace table message_archive.t_sign_record
)
comment '用户群内签到记录表';
create or replace table message_archive.t_user_levels
CREATE TABLE IF NOT EXISTS t_social_edges_daily
(
id bigint auto_increment
primary key,
stat_date date not null comment '统计日期',
group_id varchar(100) not null comment '群ID',
from_user_id varchar(100) not null comment '互动发起方',
to_user_id varchar(100) not null comment '互动接收方',
mention_count int default 0 not null comment '@次数',
reply_count int default 0 not null comment '回复次数(预留)',
interaction_score decimal(10, 2) default 0.00 not null comment '互动强度分(可用于关系网权重)',
create_time datetime default current_timestamp() null comment '创建时间',
update_time datetime default current_timestamp() null on update current_timestamp() comment '更新时间',
constraint uk_day_group_edge
unique (stat_date, group_id, from_user_id, to_user_id)
)
comment '社交关系日边表(用于关系网和搭子榜)';
CREATE INDEX IF NOT EXISTS idx_group_day_score
on t_social_edges_daily (group_id, stat_date, interaction_score);
CREATE TABLE IF NOT EXISTS t_system_job_logs
(
id bigint auto_increment
primary key,
job_key varchar(64) not null,
triggered_at datetime default current_timestamp() null,
status varchar(32) not null,
summary varchar(255) default '' null,
detail_json longtext collate utf8mb4_bin null
check (json_valid(`detail_json`)),
duration_ms int null
);
CREATE INDEX IF NOT EXISTS idx_job_time
on t_system_job_logs (job_key, triggered_at);
CREATE TABLE IF NOT EXISTS t_system_jobs
(
job_key varchar(64) not null
primary key,
name varchar(128) not null,
description varchar(255) default '' null,
trigger_type varchar(64) not null,
trigger_config longtext collate utf8mb4_bin not null
check (json_valid(`trigger_config`)),
enabled tinyint(1) default 1 not null,
created_at datetime default current_timestamp() null,
updated_at datetime default current_timestamp() null on update current_timestamp()
);
CREATE TABLE IF NOT EXISTS t_user_levels
(
id bigint auto_increment
primary key,
@@ -513,7 +809,7 @@ create or replace table message_archive.t_user_levels
unique (user_id, group_id)
);
create or replace table message_archive.t_user_points
CREATE TABLE IF NOT EXISTS t_user_points
(
id int auto_increment
primary key,
@@ -528,13 +824,13 @@ create or replace table message_archive.t_user_points
unique (user_id, group_id)
);
create or replace table message_archive.t_user_stats
CREATE TABLE IF NOT EXISTS t_user_stats
(
id bigint auto_increment
primary key,
user_id varchar(50) not null comment '用户ID',
plugin_name varchar(50) not null comment '插件名称',
command varchar(50) not null comment '触发的命令',
command varchar(256) not null comment '触发的命令',
total_calls int default 0 not null comment '总调用次数',
success_calls int default 0 not null comment '成功调用次数',
failed_calls int default 0 not null comment '失败调用次数',
@@ -545,7 +841,13 @@ create or replace table message_archive.t_user_stats
)
comment '用户使用统计表';
create or replace table message_archive.t_value_rank_snapshot
CREATE INDEX IF NOT EXISTS idx_last_used_at
on t_user_stats (last_used_at);
CREATE INDEX IF NOT EXISTS idx_user_id
on t_user_stats (user_id);
CREATE TABLE IF NOT EXISTS t_value_rank_snapshot
(
id bigint auto_increment
primary key,
@@ -559,24 +861,40 @@ create or replace table message_archive.t_value_rank_snapshot
msg_count_7d int default 0 not null comment '7日发言数',
active_days_30 int default 0 not null comment '30日活跃天数',
inactive_days int default 0 not null comment '距今未发言天数',
score_detail_json json null comment '分项得分明细',
created_at datetime default current_timestamp() not null comment '创建时间',
updated_at datetime default current_timestamp() not null on update current_timestamp() comment '更新时间',
score_detail_json longtext collate utf8mb4_bin null comment '分项得分明细'
check (json_valid(`score_detail_json`)),
created_at datetime default current_timestamp() not null,
updated_at datetime default current_timestamp() not null on update current_timestamp(),
constraint uniq_day_group_user
unique (stat_date, group_id, user_id)
)
comment '身价日快照表';
create or replace index idx_group_day_rank
on message_archive.t_value_rank_snapshot (group_id, stat_date, rank_no);
CREATE INDEX IF NOT EXISTS idx_group_day_rank
on t_value_rank_snapshot (group_id, stat_date, rank_no);
create or replace index idx_last_used_at
on message_archive.t_user_stats (last_used_at);
CREATE TABLE IF NOT EXISTS t_value_rank_social_daily
(
id bigint auto_increment
primary key,
stat_date date not null comment '统计日期',
group_id varchar(100) not null comment '群ID',
user_id varchar(100) not null comment '用户ID',
mentioned_count int default 0 not null comment '被@次数(入度)',
mention_others_count int default 0 not null comment '@他人次数(出度)',
unique_interactors int default 0 not null comment '与其发生互动的去重人数',
interaction_score decimal(10, 2) default 0.00 not null comment '社交影响力分',
create_time datetime default current_timestamp() null comment '创建时间',
update_time datetime default current_timestamp() null on update current_timestamp() comment '更新时间',
constraint uk_day_group_user
unique (stat_date, group_id, user_id)
)
comment 'Value Rank 社交日汇总表';
create or replace index idx_user_id
on message_archive.t_user_stats (user_id);
CREATE INDEX IF NOT EXISTS idx_group_day_score
on t_value_rank_social_daily (group_id, stat_date, interaction_score);
create or replace table message_archive.t_wechat_contacts
CREATE TABLE IF NOT EXISTS t_wechat_contacts
(
id int auto_increment
primary key,
@@ -608,7 +926,7 @@ create or replace table message_archive.t_wechat_contacts
)
comment '微信联系人信息表';
create or replace table message_archive.t_xiuxian_clan
CREATE TABLE IF NOT EXISTS t_xiuxian_clan
(
clan_id bigint auto_increment comment '门派ID'
primary key,
@@ -620,7 +938,7 @@ create or replace table message_archive.t_xiuxian_clan
)
comment '门派表' collate = utf8mb4_unicode_ci;
create or replace table message_archive.t_xiuxian_item
CREATE TABLE IF NOT EXISTS t_xiuxian_item
(
item_id int auto_increment comment '物品ID'
primary key,
@@ -632,7 +950,7 @@ create or replace table message_archive.t_xiuxian_item
)
comment '物品定义表' collate = utf8mb4_unicode_ci;
create or replace table message_archive.t_xiuxian_player
CREATE TABLE IF NOT EXISTS t_xiuxian_player
(
user_id varchar(100) not null comment '平台用户ID'
primary key,
@@ -647,12 +965,12 @@ create or replace table message_archive.t_xiuxian_player
status_until datetime null comment '状态到期时间',
last_cultivate_time datetime null comment '上次闭关开始时间',
constraint fk_clan_id
foreign key (clan_id) references message_archive.t_xiuxian_clan (clan_id)
foreign key (clan_id) references t_xiuxian_clan (clan_id)
on delete set null
)
comment '玩家核心数据表' collate = utf8mb4_unicode_ci;
create or replace table message_archive.t_xiuxian_inventory
CREATE TABLE IF NOT EXISTS t_xiuxian_inventory
(
id bigint auto_increment comment '背包条目ID'
primary key,
@@ -662,17 +980,17 @@ create or replace table message_archive.t_xiuxian_inventory
constraint uk_user_item
unique (user_id, item_id),
constraint fk_inv_item
foreign key (item_id) references message_archive.t_xiuxian_item (item_id)
foreign key (item_id) references t_xiuxian_item (item_id)
on delete cascade,
constraint fk_inv_user
foreign key (user_id) references message_archive.t_xiuxian_player (user_id)
foreign key (user_id) references t_xiuxian_player (user_id)
on delete cascade
)
comment '玩家背包表' collate = utf8mb4_unicode_ci;
create or replace index idx_clan_id
on message_archive.t_xiuxian_player (clan_id);
CREATE INDEX IF NOT EXISTS idx_clan_id
on t_xiuxian_player (clan_id);
create or replace index idx_realm
on message_archive.t_xiuxian_player (realm);
CREATE INDEX IF NOT EXISTS idx_realm
on t_xiuxian_player (realm);

View File

@@ -1,50 +0,0 @@
-- 消息表增加被@清单字段JSON 数组字符串)
ALTER TABLE message_archive.messages
ADD COLUMN IF NOT EXISTS mentioned_user_ids LONGTEXT NULL COMMENT '消息中被@用户ID清单JSON数组字符串' AFTER raw_payload;
-- 消息@关系明细表
CREATE TABLE IF NOT EXISTS message_archive.t_message_mentions (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
message_id VARCHAR(32) NOT NULL COMMENT '原始消息ID',
group_id VARCHAR(100) NOT NULL COMMENT '群ID',
sender_id VARCHAR(100) NOT NULL COMMENT '发送者ID@发起人)',
mentioned_user_id VARCHAR(100) NOT NULL COMMENT '被@用户ID',
stat_date DATE NOT NULL COMMENT '统计日期',
msg_time DATETIME NOT NULL COMMENT '消息时间',
create_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
UNIQUE KEY uk_message_sender_mentioned (message_id, sender_id, mentioned_user_id),
KEY idx_group_date (group_id, stat_date),
KEY idx_mentioned_group_date (mentioned_user_id, group_id, stat_date)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='消息@关系明细表';
-- 社交关系日边表(用于关系网和搭子榜)
CREATE TABLE IF NOT EXISTS message_archive.t_social_edges_daily (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
stat_date DATE NOT NULL COMMENT '统计日期',
group_id VARCHAR(100) NOT NULL COMMENT '群ID',
from_user_id VARCHAR(100) NOT NULL COMMENT '互动发起方',
to_user_id VARCHAR(100) NOT NULL COMMENT '互动接收方',
mention_count INT NOT NULL DEFAULT 0 COMMENT '@次数',
reply_count INT NOT NULL DEFAULT 0 COMMENT '回复次数(预留)',
interaction_score DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '互动强度分(可用于关系网权重)',
create_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
UNIQUE KEY uk_day_group_edge (stat_date, group_id, from_user_id, to_user_id),
KEY idx_group_day_score (group_id, stat_date, interaction_score)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='社交关系日边表(用于关系网和搭子榜)';
-- Value Rank 社交日汇总表(个人维度)
CREATE TABLE IF NOT EXISTS message_archive.t_value_rank_social_daily (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
stat_date DATE NOT NULL COMMENT '统计日期',
group_id VARCHAR(100) NOT NULL COMMENT '群ID',
user_id VARCHAR(100) NOT NULL COMMENT '用户ID',
mentioned_count INT NOT NULL DEFAULT 0 COMMENT '被@次数(入度)',
mention_others_count INT NOT NULL DEFAULT 0 COMMENT '@他人次数(出度)',
unique_interactors INT NOT NULL DEFAULT 0 COMMENT '与其发生互动的去重人数',
interaction_score DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '社交影响力分',
create_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
UNIQUE KEY uk_day_group_user (stat_date, group_id, user_id),
KEY idx_group_day_score (group_id, stat_date, interaction_score)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Value Rank 社交日汇总表';

View File

@@ -1,3 +0,0 @@
-- 为 messages 表新增 raw_payload 字段,用于存储 API 原始消息完整负载
ALTER TABLE message_archive.messages
ADD COLUMN IF NOT EXISTS raw_payload LONGTEXT NULL COMMENT 'API 原始消息完整负载(完整序列化数据)' AFTER message_xml;

View File

@@ -1,19 +0,0 @@
-- Value Rank 主快照表:用于每日身价结果持久化与趋势对比
CREATE TABLE IF NOT EXISTS message_archive.t_value_rank_snapshot (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
stat_date DATE NOT NULL COMMENT '统计日期',
group_id VARCHAR(100) NOT NULL COMMENT '群ID',
user_id VARCHAR(100) NOT NULL COMMENT '用户ID',
score DECIMAL(10,2) NOT NULL DEFAULT 0 COMMENT '身价分',
rank_no INT NOT NULL DEFAULT 0 COMMENT '排名',
title VARCHAR(50) NOT NULL DEFAULT '' COMMENT '称号',
points_total INT NOT NULL DEFAULT 0 COMMENT '积分存量',
msg_count_7d INT NOT NULL DEFAULT 0 COMMENT '7日发言数',
active_days_30 INT NOT NULL DEFAULT 0 COMMENT '30日活跃天数',
inactive_days INT NOT NULL DEFAULT 0 COMMENT '距今未发言天数',
score_detail_json JSON NULL COMMENT '分项得分明细',
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
UNIQUE KEY uniq_day_group_user (stat_date, group_id, user_id),
KEY idx_group_day_rank (group_id, stat_date, rank_no)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='身价日快照表';

View File

@@ -1,19 +0,0 @@
-- 后台管理员账号体系:数据库账号表
-- 说明:
-- 1. 使用 t_admin_ 前缀,便于后台管理相关表快速定位;
-- 2. 密码字段保存的是哈希值(非明文);
-- 3. status 可用于后续封禁/停用后台账号。
CREATE TABLE IF NOT EXISTS message_archive.t_admin_accounts (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(64) NOT NULL COMMENT '登录用户名',
password_hash VARCHAR(255) NOT NULL COMMENT '口令哈希',
display_name VARCHAR(64) NULL COMMENT '展示名称',
status TINYINT NOT NULL DEFAULT 1 COMMENT '状态1启用0禁用',
last_login_at DATETIME NULL COMMENT '最近登录时间',
last_login_ip VARCHAR(64) NULL COMMENT '最近登录IP',
create_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
UNIQUE KEY uk_admin_username (username)
) COMMENT='后台管理员账号表';

View File

@@ -1,21 +0,0 @@
-- 趣味指令剧本规则表
-- 说明:用于配置“文本/事件触发 -> 多媒体响应”玩法规则。
CREATE TABLE IF NOT EXISTS t_fun_command_rule (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
rule_name VARCHAR(128) NOT NULL,
scope_type VARCHAR(20) NOT NULL DEFAULT 'global',
scope_id VARCHAR(100) NOT NULL DEFAULT '',
trigger_type VARCHAR(20) NOT NULL DEFAULT 'exact',
trigger_text VARCHAR(500) NOT NULL DEFAULT '',
event_key VARCHAR(64) NOT NULL DEFAULT '',
responses_json JSON NOT NULL,
priority INT NOT NULL DEFAULT 100,
cooldown_seconds INT NOT NULL DEFAULT 0,
enabled TINYINT(1) NOT NULL DEFAULT 1,
updated_by VARCHAR(100) NOT NULL DEFAULT 'system',
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX idx_scope_enabled_priority (scope_type, scope_id, enabled, priority),
INDEX idx_trigger_type (trigger_type),
INDEX idx_event_key (event_key)
);

View File

@@ -1,17 +0,0 @@
CREATE TABLE IF NOT EXISTS message_archive.t_emoji_assets (
md5 VARCHAR(64) PRIMARY KEY COMMENT '表情MD5',
total_length INT NOT NULL DEFAULT 0 COMMENT '表情总长度',
semantic_text VARCHAR(255) DEFAULT '' COMMENT '主语义文本',
semantic_aliases LONGTEXT NULL COMMENT '语义别名列表(JSON数组)',
semantic_source VARCHAR(64) DEFAULT '' COMMENT '语义来源字段如desc/emojiattr',
preview_url VARCHAR(255) DEFAULT '' COMMENT '本地预览图路径',
sample_message_id VARCHAR(32) DEFAULT '' COMMENT '样例消息ID',
sample_group_id VARCHAR(100) DEFAULT '' COMMENT '样例群ID',
sample_sender VARCHAR(100) DEFAULT '' COMMENT '样例发送者',
first_seen_at DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '首次看到时间',
last_seen_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最近看到时间',
created_at DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
INDEX idx_emoji_last_seen (last_seen_at),
INDEX idx_emoji_preview (preview_url)
);