SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for conversation
-- ----------------------------
DROP TABLE IF EXISTS `conversation`;
CREATE TABLE `conversation`  (
                                 `id` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
                                 `title` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '标题',
                                 `type` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '类型',
                                 `case_id` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '案件ID',
                                 `user_id` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '用户ID',
                                 `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
                                 `update_time` datetime NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
                                 PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = '会话记录表' ROW_FORMAT = DYNAMIC;

SET FOREIGN_KEY_CHECKS = 1;

DROP TABLE IF EXISTS `conversation_qa`;
CREATE TABLE `conversation_qa`  (
                                    `id` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
                                    `type` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '问答类型 0：DIFY问答 1：NX_LLM问答',
                                    `intent_type` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '意图类型 0：指标结果 1：案件分析结果 2：案件概况 3：案件证据指引',
                                    `question` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
                                    `complete_question` text CHARACTER SET utf8 COLLATE utf8_bin NULL,
                                    `question_time` datetime NOT NULL,
                                    `answer` text CHARACTER SET utf8 COLLATE utf8_bin NULL,
                                    `complete_answer` text CHARACTER SET utf8 COLLATE utf8_bin NULL,
                                    `answer_time` datetime NULL DEFAULT NULL,
                                    `time_interval` int(11) NULL DEFAULT NULL,
                                    `user_id` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
                                    `case_id` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
                                    `conversation_id` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
                                    `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
                                    `update_time` datetime NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
                                    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_bin ROW_FORMAT = DYNAMIC;

SET FOREIGN_KEY_CHECKS = 1;

alter table model_case
    add knowledge_base_id varchar(64) null comment '知识库id' after id;