kboss/b/cntoai/chat_tables.sql
2026-05-22 19:18:37 +08:00

24 lines
1.3 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.

-- 多轮对话:请先执行本脚本创建表后再使用 chat_send / chat_session_* 接口
CREATE TABLE IF NOT EXISTS `chat_session` (
`id` varchar(64) NOT NULL COMMENT '会话ID',
`userid` varchar(64) NOT NULL COMMENT '用户ID',
`model` varchar(128) NOT NULL COMMENT '模型名称',
`title` varchar(255) DEFAULT NULL COMMENT '会话标题(首条问题摘要)',
`created_at` datetime DEFAULT current_timestamp() COMMENT '创建时间',
`updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT '更新时间',
PRIMARY KEY (`id`),
KEY `idx_userid_updated` (`userid`, `updated_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='模型对话会话';
CREATE TABLE IF NOT EXISTS `chat_message` (
`id` varchar(64) NOT NULL COMMENT '消息ID',
`session_id` varchar(64) NOT NULL COMMENT '会话ID',
`role` varchar(32) NOT NULL COMMENT '角色: user / assistant / system',
`content` mediumtext COMMENT '消息内容纯文本或JSON',
`content_type` varchar(32) DEFAULT 'text' COMMENT 'text / mixed',
`created_at` datetime DEFAULT current_timestamp() COMMENT '创建时间',
PRIMARY KEY (`id`),
KEY `idx_session_id` (`session_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='模型对话消息';