| | |
| | | `user_id` bigint(20) NOT NULL COMMENT '用户 ID', |
| | | `tenant_id` bigint(20) DEFAULT NULL COMMENT '租户', |
| | | `last_message_time` datetime DEFAULT NULL COMMENT '最后消息时间', |
| | | `memory_summary` longtext COMMENT '记忆摘要', |
| | | `memory_facts` text COMMENT '关键事实', |
| | | `pinned` tinyint(1) DEFAULT '0' COMMENT '是否置顶', |
| | | `status` int(11) DEFAULT '1' COMMENT '状态', |
| | | `deleted` int(11) DEFAULT '0' COMMENT '删除标记', |
| | | `create_time` datetime DEFAULT NULL COMMENT '创建时间', |
| | |
| | | `seq_no` int(11) NOT NULL COMMENT '消息序号', |
| | | `role` varchar(32) NOT NULL COMMENT '消息角色', |
| | | `content` longtext COMMENT '消息内容', |
| | | `content_length` int(11) DEFAULT NULL COMMENT '内容长度', |
| | | `user_id` bigint(20) NOT NULL COMMENT '用户 ID', |
| | | `tenant_id` bigint(20) DEFAULT NULL COMMENT '租户', |
| | | `deleted` int(11) DEFAULT '0' COMMENT '删除标记', |
| | |
| | | EXECUTE builtin_code_stmt; |
| | | DEALLOCATE PREPARE builtin_code_stmt; |
| | | |
| | | SET @chat_session_pinned_exists := ( |
| | | SELECT COUNT(1) |
| | | FROM `information_schema`.`COLUMNS` |
| | | WHERE `TABLE_SCHEMA` = DATABASE() |
| | | AND `TABLE_NAME` = 'sys_ai_chat_session' |
| | | AND `COLUMN_NAME` = 'pinned' |
| | | ); |
| | | SET @chat_session_pinned_sql := IF( |
| | | @chat_session_pinned_exists = 0, |
| | | 'ALTER TABLE `sys_ai_chat_session` ADD COLUMN `pinned` tinyint(1) DEFAULT ''0'' COMMENT ''是否置顶'' AFTER `last_message_time`', |
| | | 'SELECT 1' |
| | | ); |
| | | PREPARE chat_session_pinned_stmt FROM @chat_session_pinned_sql; |
| | | EXECUTE chat_session_pinned_stmt; |
| | | DEALLOCATE PREPARE chat_session_pinned_stmt; |
| | | |
| | | SET @chat_session_summary_exists := ( |
| | | SELECT COUNT(1) |
| | | FROM `information_schema`.`COLUMNS` |
| | | WHERE `TABLE_SCHEMA` = DATABASE() |
| | | AND `TABLE_NAME` = 'sys_ai_chat_session' |
| | | AND `COLUMN_NAME` = 'memory_summary' |
| | | ); |
| | | SET @chat_session_summary_sql := IF( |
| | | @chat_session_summary_exists = 0, |
| | | 'ALTER TABLE `sys_ai_chat_session` ADD COLUMN `memory_summary` longtext COMMENT ''记忆摘要'' AFTER `last_message_time`', |
| | | 'SELECT 1' |
| | | ); |
| | | PREPARE chat_session_summary_stmt FROM @chat_session_summary_sql; |
| | | EXECUTE chat_session_summary_stmt; |
| | | DEALLOCATE PREPARE chat_session_summary_stmt; |
| | | |
| | | SET @chat_session_facts_exists := ( |
| | | SELECT COUNT(1) |
| | | FROM `information_schema`.`COLUMNS` |
| | | WHERE `TABLE_SCHEMA` = DATABASE() |
| | | AND `TABLE_NAME` = 'sys_ai_chat_session' |
| | | AND `COLUMN_NAME` = 'memory_facts' |
| | | ); |
| | | SET @chat_session_facts_sql := IF( |
| | | @chat_session_facts_exists = 0, |
| | | 'ALTER TABLE `sys_ai_chat_session` ADD COLUMN `memory_facts` text COMMENT ''关键事实'' AFTER `memory_summary`', |
| | | 'SELECT 1' |
| | | ); |
| | | PREPARE chat_session_facts_stmt FROM @chat_session_facts_sql; |
| | | EXECUTE chat_session_facts_stmt; |
| | | DEALLOCATE PREPARE chat_session_facts_stmt; |
| | | |
| | | SET @chat_message_length_exists := ( |
| | | SELECT COUNT(1) |
| | | FROM `information_schema`.`COLUMNS` |
| | | WHERE `TABLE_SCHEMA` = DATABASE() |
| | | AND `TABLE_NAME` = 'sys_ai_chat_message' |
| | | AND `COLUMN_NAME` = 'content_length' |
| | | ); |
| | | SET @chat_message_length_sql := IF( |
| | | @chat_message_length_exists = 0, |
| | | 'ALTER TABLE `sys_ai_chat_message` ADD COLUMN `content_length` int(11) DEFAULT NULL COMMENT ''内容长度'' AFTER `content`', |
| | | 'SELECT 1' |
| | | ); |
| | | PREPARE chat_message_length_stmt FROM @chat_message_length_sql; |
| | | EXECUTE chat_message_length_stmt; |
| | | DEALLOCATE PREPARE chat_message_length_stmt; |
| | | |
| | | BEGIN; |
| | | INSERT INTO `sys_ai_prompt` |
| | | (`id`, `name`, `code`, `scene`, `system_prompt`, `user_prompt_template`, `tenant_id`, `status`, `deleted`, `create_time`, `create_by`, `update_time`, `update_by`, `memo`) |