SET NAMES utf8mb4;
SET
FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for tb_bot
-- ----------------------------
CREATE TABLE `tb_bot`
(
    `id`            bigint UNSIGNED NOT NULL COMMENT '主键ID',
    `alias`         varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '别名',
    `dept_id`       bigint UNSIGNED NOT NULL COMMENT '部门ID',
    `tenant_id`     bigint UNSIGNED NOT NULL COMMENT '租户ID',
    `category_id`   bigint UNSIGNED NULL DEFAULT NULL COMMENT '分类ID',
    `title`         varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '标题',
    `description`   varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '描述',
    `icon`          varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '图标',
    `model_id`      bigint UNSIGNED NULL DEFAULT NULL COMMENT '模型 ID',
    `model_options` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '模型配置',
    `status`        int NULL DEFAULT 0 COMMENT '数据状态',
    `options`       text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '选项',
    `created`       datetime NULL DEFAULT NULL COMMENT '创建时间',
    `created_by`    bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建者ID',
    `modified`      datetime NULL DEFAULT NULL COMMENT '修改时间',
    `modified_by`   bigint UNSIGNED NULL DEFAULT NULL COMMENT '修改者ID',
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE INDEX `tb_ai_bot_alias_uindex`(`alias`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = 'bot表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_bot_category
-- ----------------------------
CREATE TABLE `tb_bot_category`
(
    `id`            bigint UNSIGNED NOT NULL COMMENT '主键',
    `category_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '分类名称',
    `sort_no`       int NULL DEFAULT 0 COMMENT '排序',
    `status`        int                                                          NOT NULL DEFAULT 0 COMMENT '数据状态',
    `created`       datetime                                                     NOT NULL COMMENT '创建时间',
    `created_by`    bigint UNSIGNED NOT NULL COMMENT '创建者',
    `modified`      datetime                                                     NOT NULL COMMENT '修改时间',
    `modified_by`   bigint UNSIGNED NOT NULL COMMENT '修改者',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = 'bot分类' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for tb_bot_document_collection
-- ----------------------------
CREATE TABLE `tb_bot_document_collection`
(
    `id`                     bigint UNSIGNED NOT NULL AUTO_INCREMENT,
    `bot_id`                 bigint UNSIGNED NULL DEFAULT NULL,
    `document_collection_id` bigint UNSIGNED NULL DEFAULT NULL,
    `options`                text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL,
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE INDEX `uni_bot_document_collection`(`bot_id`, `document_collection_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 36 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = 'bot绑定的知识库' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for chat_session
-- ----------------------------
CREATE TABLE `chat_session`
(
    `id`                   bigint UNSIGNED NOT NULL COMMENT '会话ID',
    `tenant_id`            bigint UNSIGNED NOT NULL COMMENT '租户ID',
    `dept_id`              bigint UNSIGNED NOT NULL COMMENT '部门ID',
    `user_id`              bigint UNSIGNED NOT NULL COMMENT '用户ID',
    `user_account`         varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '用户账号',
    `assistant_id`         bigint UNSIGNED NOT NULL COMMENT '助手ID',
    `assistant_code`       varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '助手编码',
    `assistant_name`       varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '助手名称',
    `title`                varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '会话标题',
    `last_message_preview` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '' COMMENT '最后消息预览',
    `last_sender_id`       bigint UNSIGNED NULL DEFAULT NULL COMMENT '最后发送方ID',
    `last_sender_name`     varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '最后发送方名称',
    `message_count`        int NOT NULL DEFAULT 0 COMMENT '消息数量',
    `access_at`            datetime NOT NULL COMMENT '访问时间',
    `last_message_at`      datetime NULL DEFAULT NULL COMMENT '最后消息时间',
    `created`              datetime NOT NULL COMMENT '创建时间',
    `created_by`           bigint UNSIGNED NOT NULL COMMENT '创建者',
    `modified`             datetime NOT NULL COMMENT '修改时间',
    `modified_by`          bigint UNSIGNED NOT NULL COMMENT '修改者',
    `is_deleted`           tinyint NOT NULL DEFAULT 0 COMMENT '逻辑删除',
    PRIMARY KEY (`id`) USING BTREE,
    KEY `idx_user_deleted_access` (`user_id`, `is_deleted`, `access_at`, `id`) USING BTREE,
    KEY `idx_user_assistant_deleted_access` (`user_id`, `assistant_id`, `is_deleted`, `access_at`, `id`) USING BTREE,
    KEY `idx_modified` (`modified`, `id`) USING BTREE,
    KEY `idx_access_at` (`access_at`, `id`) USING BTREE
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '聊天会话热数据表';

-- ----------------------------
-- Table structure for chat_log_template
-- ----------------------------
CREATE TABLE `chat_log_template`
(
    `id`              bigint UNSIGNED NOT NULL COMMENT '主键',
    `tenant_id`       bigint UNSIGNED NOT NULL COMMENT '租户ID',
    `dept_id`         bigint UNSIGNED NOT NULL COMMENT '部门ID',
    `session_id`      bigint UNSIGNED NOT NULL COMMENT '会话ID',
    `user_id`         bigint UNSIGNED NOT NULL COMMENT '用户ID',
    `assistant_id`    bigint UNSIGNED NOT NULL COMMENT '助手ID',
    `sender_id`       bigint UNSIGNED NULL DEFAULT NULL COMMENT '发送方ID',
    `sender_name`     varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '发送方名称',
    `sender_role`     varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '发送方角色',
    `content_type`    varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '内容类型',
    `content_text`    longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '文本内容',
    `content_payload` json NULL COMMENT '结构化内容',
    `created`         datetime NOT NULL COMMENT '发送时间',
    `created_by`      bigint UNSIGNED NOT NULL COMMENT '创建者',
    `sync_version`    bigint UNSIGNED NOT NULL COMMENT '同步版本',
    PRIMARY KEY (`id`) USING BTREE,
    KEY `idx_session_created` (`session_id`, `created`, `id`) USING BTREE,
    KEY `idx_user_created` (`user_id`, `created`, `id`) USING BTREE,
    KEY `idx_assistant_created` (`assistant_id`, `created`, `id`) USING BTREE
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '聊天消息月表模板';

-- ----------------------------
-- Table structure for chat_sync_checkpoint
-- ----------------------------
CREATE TABLE `chat_sync_checkpoint`
(
    `id`                bigint UNSIGNED NOT NULL COMMENT '主键',
    `sync_code`         varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '同步编码',
    `shard_key`         varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '同步游标键',
    `cursor_table`      varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '游标表名',
    `cursor_time`       datetime NULL DEFAULT NULL COMMENT '游标时间',
    `cursor_id`         bigint UNSIGNED NULL DEFAULT NULL COMMENT '游标ID',
    `last_success_time` datetime NULL DEFAULT NULL COMMENT '最后成功时间',
    `last_batch_size`   int NULL DEFAULT 0 COMMENT '最后批次大小',
    `status`            varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT 'READY' COMMENT '状态',
    `remark`            varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '备注',
    `modified`          datetime NOT NULL COMMENT '修改时间',
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE KEY `uk_sync` (`sync_code`, `shard_key`) USING BTREE
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '聊天同步检查点';

-- ----------------------------
-- Table structure for chat_persist_dead_letter
-- ----------------------------
CREATE TABLE `chat_persist_dead_letter`
(
    `id`                bigint UNSIGNED NOT NULL COMMENT '主键',
    `topic`             varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT 'topic',
    `stream_key`        varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT 'stream key',
    `stream_message_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'stream message id',
    `event_id`          varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '事件ID',
    `session_id`        bigint UNSIGNED NULL DEFAULT NULL COMMENT '会话ID',
    `payload`           json NULL COMMENT '事件负载',
    `retry_count`       int NOT NULL DEFAULT 0 COMMENT '重试次数',
    `error_message`     varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '错误信息',
    `first_failed_at`   datetime NOT NULL COMMENT '首次失败时间',
    `last_failed_at`    datetime NOT NULL COMMENT '最后失败时间',
    `status`            varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '状态',
    `created`           datetime NOT NULL COMMENT '创建时间',
    `modified`          datetime NOT NULL COMMENT '修改时间',
    PRIMARY KEY (`id`) USING BTREE,
    KEY `idx_chat_persist_dead_letter_event` (`event_id`) USING BTREE,
    KEY `idx_chat_persist_dead_letter_session` (`session_id`) USING BTREE,
    KEY `idx_chat_persist_dead_letter_status` (`status`, `last_failed_at`) USING BTREE
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '聊天持久化死信表';

-- ----------------------------
-- Table structure for tb_bot_model
-- ----------------------------
CREATE TABLE `tb_bot_model`
(
    `id`       bigint UNSIGNED NOT NULL,
    `bot_id`   bigint UNSIGNED NULL DEFAULT NULL,
    `model_id` bigint UNSIGNED NULL DEFAULT NULL,
    `options`  text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL,
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = 'bot绑定的大模型' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_bot_plugin
-- ----------------------------
CREATE TABLE `tb_bot_plugin`
(
    `id`             bigint UNSIGNED NOT NULL,
    `bot_id`         bigint UNSIGNED NULL DEFAULT NULL,
    `plugin_item_id` bigint UNSIGNED NULL DEFAULT NULL,
    `options`        text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL,
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE INDEX `uni_bot_plugin`(`bot_id`, `plugin_item_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = 'bot绑定的插件' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_bot_recently_used
-- ----------------------------
CREATE TABLE `tb_bot_recently_used`
(
    `id`         bigint UNSIGNED NOT NULL COMMENT '主键',
    `bot_id`     bigint UNSIGNED NOT NULL COMMENT 'botId',
    `created`    datetime NOT NULL COMMENT '创建时间',
    `created_by` bigint UNSIGNED NOT NULL COMMENT '创建者',
    `sort_no`    int NULL DEFAULT 0 COMMENT '排序',
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE INDEX `uni_bot_recently_used`(`created_by`, `bot_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '最近使用' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for tb_bot_workflow
-- ----------------------------
CREATE TABLE `tb_bot_workflow`
(
    `id`          bigint UNSIGNED NOT NULL,
    `bot_id`      bigint UNSIGNED NULL DEFAULT NULL,
    `workflow_id` bigint UNSIGNED NULL DEFAULT NULL,
    `options`     text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL,
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE INDEX `uni_bot_workflow`(`bot_id`, `workflow_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = 'bot绑定的工作流' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_datacenter_table
-- ----------------------------
CREATE TABLE `tb_datacenter_table`
(
    `id`                 bigint UNSIGNED NOT NULL COMMENT '主键',
    `dept_id`            bigint UNSIGNED NOT NULL COMMENT '部门ID',
    `tenant_id`          bigint UNSIGNED NOT NULL COMMENT '租户ID',
    `source_id`          bigint UNSIGNED NULL DEFAULT NULL COMMENT '数据源ID',
    `catalog_id`         bigint UNSIGNED NULL DEFAULT NULL COMMENT '目录ID',
    `table_name`         varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '数据表名',
    `table_desc`         varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT '' COMMENT '数据表描述',
    `actual_table`       varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '物理表名',
    `table_kind`         varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT 'EXTERNAL_TABLE' COMMENT '表类型',
    `access_mode`        varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT 'READ_ONLY' COMMENT '访问模式',
    `materialized_table` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '物化表名',
    `versioning_enabled` int NOT NULL DEFAULT 0 COMMENT '是否开启版本',
    `status`             int NOT NULL DEFAULT 0 COMMENT '数据状态',
    `created`            datetime NOT NULL COMMENT '创建时间',
    `created_by`         bigint UNSIGNED NOT NULL COMMENT '创建者',
    `modified`           datetime NOT NULL COMMENT '修改时间',
    `modified_by`        bigint UNSIGNED NOT NULL COMMENT '修改者',
    `options`            text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '扩展项',
    `capabilities_json`  text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '能力声明',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '数据中枢表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_datacenter_table_field
-- ----------------------------
CREATE TABLE `tb_datacenter_table_field`
(
    `id`                 bigint UNSIGNED NOT NULL COMMENT '主键',
    `table_id`           bigint UNSIGNED NOT NULL COMMENT '数据表ID',
    `field_name`         varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '字段名称',
    `source_column_name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '源字段名',
    `field_desc`         varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT '' COMMENT '字段描述',
    `field_type`         int NOT NULL COMMENT '字段类型',
    `jdbc_type`          varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'JDBC类型',
    `precision`          int NULL DEFAULT NULL COMMENT '精度',
    `scale`              int NULL DEFAULT NULL COMMENT '小数位',
    `required`           int NOT NULL DEFAULT 0 COMMENT '是否必填',
    `queryable`          int NOT NULL DEFAULT 1 COMMENT '可查询',
    `sortable`           int NOT NULL DEFAULT 1 COMMENT '可排序',
    `writable`           int NOT NULL DEFAULT 1 COMMENT '可写入',
    `indexed`            int NOT NULL DEFAULT 0 COMMENT '是否索引',
    `options`            text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '扩展项',
    `created`            datetime NOT NULL COMMENT '创建时间',
    `created_by`         bigint UNSIGNED NOT NULL COMMENT '创建者',
    `modified`           datetime NOT NULL COMMENT '修改时间',
    `modified_by`        bigint UNSIGNED NOT NULL COMMENT '修改者',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '数据中枢字段表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_document
-- ----------------------------
CREATE TABLE `tb_document`
(
    `id`            bigint UNSIGNED NOT NULL,
    `collection_id` bigint UNSIGNED NOT NULL COMMENT '知识库ID',
    `document_type` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '文档类型 pdf/word/aieditor 等',
    `document_path` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '文档路径',
    `title`         varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '标题',
    `content`       longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '内容',
    `content_type`  varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '内容类型',
    `slug`          varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'URL 别名',
    `order_no`      int NULL DEFAULT NULL COMMENT '排序序号',
    `options`       text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '其他配置项',
    `created`       datetime NULL DEFAULT NULL COMMENT '创建时间',
    `created_by`    bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建人ID',
    `modified`      datetime NULL DEFAULT NULL COMMENT '最后的修改时间',
    `modified_by`   bigint UNSIGNED NULL DEFAULT NULL COMMENT '最后的修改人的ID',
    PRIMARY KEY (`id`) USING BTREE,
    INDEX           `knowledge_id`(`collection_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '文档' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_document_chunk
-- ----------------------------
CREATE TABLE `tb_document_chunk`
(
    `id`                     bigint UNSIGNED NOT NULL,
    `document_id`            bigint UNSIGNED NOT NULL COMMENT '文档ID',
    `document_collection_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '知识库ID',
    `content`                text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '分块内容',
    `sorting`                int NULL DEFAULT NULL COMMENT '分割顺序',
    `options`                text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '扩展元信息',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '文档分块表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_document_collection
-- ----------------------------
CREATE TABLE `tb_document_collection`
(
    `id`                        bigint UNSIGNED NOT NULL COMMENT 'Id',
    `collection_type`           varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT 'DOCUMENT' COMMENT '知识库类型: DOCUMENT/FAQ',
    `alias`                     varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '别名',
    `dept_id`                   bigint UNSIGNED NOT NULL COMMENT '部门ID',
    `tenant_id`                 bigint UNSIGNED NOT NULL COMMENT '租户ID',
    `icon`                      varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'ICON',
    `title`                     varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '标题',
    `description`               varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '描述',
    `slug`                      varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'URL 别名',
    `vector_store_enable`       tinyint NULL DEFAULT NULL COMMENT '是否启用向量存储',
    `vector_store_type`         varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '向量数据库类型',
    `vector_store_collection`   varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '向量数据库集合',
    `vector_store_config`       text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '向量数据库配置',
    `vector_embed_model_id`     bigint UNSIGNED NULL DEFAULT NULL COMMENT 'Embedding 模型ID',
    `dimension_of_vector_model` int NULL DEFAULT NULL COMMENT '向量模型维度',
    `created`                   datetime NULL DEFAULT NULL COMMENT '创建时间',
    `created_by`                bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建用户ID',
    `modified`                  datetime NULL DEFAULT NULL COMMENT '最后一次修改时间',
    `modified_by`               bigint UNSIGNED NULL DEFAULT NULL COMMENT '最后一次修改用户ID',
    `options`                   text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '其他配置',
    `rerank_model_id`           bigint UNSIGNED NULL DEFAULT NULL COMMENT '重排模型id',
    `search_engine_enable`      tinyint NULL DEFAULT NULL COMMENT '是否启用搜索引擎',
    `english_name`              varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '英文名称',
    `category_id`               bigint UNSIGNED NULL DEFAULT NULL COMMENT '分类ID',
    `visibility_scope`          varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '可见范围',
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE INDEX `tb_ai_knowledge_alias_uindex`(`alias`) USING BTREE,
    INDEX `idx_collection_type`(`collection_type`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '知识库' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for tb_document_collection_category
-- ----------------------------
CREATE TABLE `tb_document_collection_category`
(
    `id`            bigint UNSIGNED NOT NULL COMMENT '主键',
    `category_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '分类名称',
    `sort_no`       int NULL DEFAULT 0 COMMENT '排序',
    `status`        int NOT NULL DEFAULT 0 COMMENT '数据状态',
    `created`       datetime NOT NULL COMMENT '创建时间',
    `created_by`    bigint UNSIGNED NOT NULL COMMENT '创建者',
    `modified`      datetime NOT NULL COMMENT '修改时间',
    `modified_by`   bigint UNSIGNED NOT NULL COMMENT '修改者',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for tb_faq_category
-- ----------------------------
CREATE TABLE `tb_faq_category`
(
    `id`            bigint UNSIGNED NOT NULL COMMENT '主键',
    `collection_id` bigint UNSIGNED NOT NULL COMMENT '知识库ID',
    `parent_id`     bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '父分类ID，0表示根',
    `ancestors`     varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '0' COMMENT '祖先路径(逗号分隔)',
    `level_no`      tinyint UNSIGNED NOT NULL DEFAULT 1 COMMENT '层级(1-3)',
    `category_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '分类名称',
    `sort_no`       int NOT NULL DEFAULT 0 COMMENT '排序',
    `is_default`    tinyint NOT NULL DEFAULT 0 COMMENT '是否默认分类',
    `status`        int NOT NULL DEFAULT 0 COMMENT '数据状态',
    `created`       datetime NULL DEFAULT NULL COMMENT '创建时间',
    `created_by`    bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建人',
    `modified`      datetime NULL DEFAULT NULL COMMENT '更新时间',
    `modified_by`   bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人',
    PRIMARY KEY (`id`) USING BTREE,
    INDEX `idx_faq_category_collection_parent_sort`(`collection_id`, `parent_id`, `sort_no`) USING BTREE,
    INDEX `idx_faq_category_collection_level`(`collection_id`, `level_no`) USING BTREE,
    INDEX `idx_faq_category_collection_status`(`collection_id`, `status`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = 'FAQ分类' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for tb_faq_item
-- ----------------------------
CREATE TABLE `tb_faq_item`
(
    `id`          bigint UNSIGNED NOT NULL COMMENT '主键',
    `collection_id` bigint UNSIGNED NOT NULL COMMENT '知识库ID',
    `category_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT 'FAQ分类ID',
    `question`    varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '问题',
    `answer_html` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '答案HTML',
    `answer_text` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '答案纯文本',
    `order_no`    int NULL DEFAULT 0 COMMENT '排序',
    `options`     text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '扩展项',
    `created`     datetime NULL DEFAULT NULL COMMENT '创建时间',
    `created_by`  bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建人',
    `modified`    datetime NULL DEFAULT NULL COMMENT '更新时间',
    `modified_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人',
    PRIMARY KEY (`id`) USING BTREE,
    INDEX `idx_faq_collection_id`(`collection_id`) USING BTREE,
    INDEX `idx_faq_collection_order`(`collection_id`, `order_no`) USING BTREE,
    INDEX `idx_faq_collection_category_order`(`collection_id`, `category_id`, `order_no`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = 'FAQ条目' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for tb_document_history
-- ----------------------------
CREATE TABLE `tb_document_history`
(
    `id`                bigint UNSIGNED NOT NULL AUTO_INCREMENT,
    `document_id`       bigint NULL DEFAULT NULL COMMENT '修改的文档ID',
    `old_title`         varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '旧标题',
    `new_title`         varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '新标题',
    `old_content`       text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '旧内容',
    `new_content`       text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '新内容',
    `old_document_type` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '旧的文档类型',
    `new_document_type` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '新的额文档类型',
    `created`           datetime NULL DEFAULT NULL COMMENT '创建时间',
    `created_by`        bigint NULL DEFAULT NULL COMMENT '创建人ID',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '文档历史记录' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_model
-- ----------------------------
CREATE TABLE `tb_model`
(
    `id`                     bigint UNSIGNED NOT NULL COMMENT 'ID',
    `dept_id`                bigint UNSIGNED NOT NULL COMMENT '部门ID',
    `tenant_id`              bigint UNSIGNED NOT NULL COMMENT '租户ID',
    `provider_id`            bigint UNSIGNED NULL DEFAULT NULL COMMENT '供应商id',
    `title`                  varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '标题或名称',
    `icon`                   varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'ICON',
    `description`            varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '描述',
    `endpoint`               varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '大模型请求地址',
    `request_path`           varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '请求路径',
    `model_name`             varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '大模型名称',
    `api_key`                varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '大模型 API KEY',
    `extra_config`           text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '大模型其他属性配置',
    `options`                text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '其他配置内容',
    `group_name`             varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '分组名称',
    `model_type`             varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '模型类型: chatModel/embeddingModel/rerankModel/orc..',
    `with_used`              tinyint NULL DEFAULT NULL COMMENT '是否使用',
    `support_thinking`       tinyint NULL DEFAULT NULL COMMENT '是否支持推理',
    `support_tool`           tinyint NULL DEFAULT NULL COMMENT '是否支持工具',
    `support_image`          tinyint NULL DEFAULT NULL COMMENT '是否支持图片',
    `support_image_b64_only` tinyint NULL DEFAULT NULL COMMENT '仅支持 base64 的图片类型',
    `support_video`          tinyint NULL DEFAULT NULL COMMENT '是否支持视频',
    `support_audio`          tinyint NULL DEFAULT NULL COMMENT '是否支持音频',
    `support_free`           tinyint NULL DEFAULT NULL COMMENT '是否免费',
    `support_tool_message`   tinyint NULL DEFAULT NULL COMMENT '是否支持tool消息',
    `invoke_code`            varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '统一模型调用对外标识',
    `publish_enabled`        tinyint NULL DEFAULT 0 COMMENT '是否开启统一模型调用发布',
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE INDEX `uni_model_invoke_code`(`invoke_code`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '大模型管理' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for tb_model_provider
-- ----------------------------
CREATE TABLE `tb_model_provider`
(
    `id`            bigint UNSIGNED NOT NULL COMMENT 'id',
    `provider_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '供应商名称',
    `provider_type` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '不同的 client 实现，默认为 openai',
    `icon`          varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '图标',
    `api_key`       varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'apiKey',
    `endpoint`      varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'endPoint',
    `chat_path`     varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '对话地址',
    `embed_path`    varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '向量地址',
    `rerank_path`   varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '重排路径',
    `created`       datetime                                                      NOT NULL COMMENT '创建时间',
    `created_by`    bigint UNSIGNED NOT NULL COMMENT '创建者',
    `modified`      datetime                                                      NOT NULL COMMENT '修改时间',
    `modified_by`   bigint UNSIGNED NOT NULL COMMENT '修改者',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '大模型供应商，比如 Aliyun/Gitee/火山引擎 等' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_plugin
-- ----------------------------
CREATE TABLE `tb_plugin`
(
    `id`          bigint UNSIGNED NOT NULL COMMENT '插件id',
    `alias`       varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '别名',
    `name`        varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '名称',
    `description` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '描述',
    `type`        int NULL DEFAULT NULL COMMENT '类型',
    `base_url`    varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '基础URL',
    `auth_type`   varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '认证方式  【apiKey/none】',
    `created`     datetime NULL DEFAULT NULL COMMENT '创建时间',
    `icon`        varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '图标地址',
    `position`    varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '认证参数位置 【headers, query】',
    `headers`     varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '请求头',
    `token_key`   varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'token键',
    `token_value` varchar(2000) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'token值',
    `dept_id`     bigint NULL DEFAULT NULL COMMENT '部门id',
    `tenant_id`   bigint NULL DEFAULT NULL COMMENT '租户id',
    `created_by`  bigint NULL DEFAULT NULL COMMENT '创建人',
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE INDEX `tb_ai_plugin_alias_uindex`(`alias`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '插件表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_plugin_category
-- ----------------------------
CREATE TABLE `tb_plugin_category`
(
    `id`         bigint UNSIGNED NOT NULL AUTO_INCREMENT,
    `name`       varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
    `created_at` datetime NULL DEFAULT NULL,
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 44 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '插件分类' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_plugin_category_mapping
-- ----------------------------
CREATE TABLE `tb_plugin_category_mapping`
(
    `category_id` bigint UNSIGNED NOT NULL,
    `plugin_id`   bigint UNSIGNED NOT NULL
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '插件分类关联表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_plugin_item
-- ----------------------------
CREATE TABLE `tb_plugin_item`
(
    `id`             bigint UNSIGNED NOT NULL COMMENT '插件工具id',
    `plugin_id`      bigint UNSIGNED NOT NULL COMMENT '插件id',
    `name`           varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '名称',
    `description`    varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '描述',
    `base_path`      varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '基础路径',
    `created`        datetime NULL DEFAULT NULL COMMENT '创建时间',
    `status`         int NULL DEFAULT 0 COMMENT '是否启用',
    `input_data`     text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '输入参数',
    `output_data`    text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '输出参数',
    `request_method` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '请求方式【Post, Get, Put, Delete】',
    `service_status` int NULL DEFAULT NULL COMMENT '服务状态[0 下线 1 上线]',
    `debug_status`   int NULL DEFAULT NULL COMMENT '调试状态【0失败 1成功】',
    `english_name`   varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '英文名称',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '插件工具表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_resource
-- ----------------------------
CREATE TABLE `tb_resource`
(
    `id`            bigint UNSIGNED NOT NULL COMMENT '主键',
    `dept_id`       bigint UNSIGNED NOT NULL COMMENT '部门ID',
    `tenant_id`     bigint UNSIGNED NOT NULL COMMENT '租户ID',
    `resource_type` int                                                           NOT NULL COMMENT '素材类型',
    `resource_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '素材名称',
    `suffix`        varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci  NOT NULL COMMENT '后缀',
    `resource_url`  varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '素材地址',
    `origin`        int                                                           NOT NULL DEFAULT 0 COMMENT '素材来源',
    `status`        int                                                           NOT NULL DEFAULT 0 COMMENT '数据状态',
    `created`       datetime                                                      NOT NULL COMMENT '创建时间',
    `created_by`    bigint UNSIGNED NOT NULL COMMENT '创建者',
    `modified`      datetime                                                      NOT NULL COMMENT '修改时间',
    `modified_by`   bigint UNSIGNED NOT NULL COMMENT '修改者',
    `options`       text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '扩展项',
    `file_size`     bigint UNSIGNED NULL DEFAULT NULL COMMENT '文件大小',
    `category_id`   bigint UNSIGNED NULL DEFAULT NULL COMMENT '分类ID',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '素材库' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_resource_category
-- ----------------------------
CREATE TABLE `tb_resource_category`
(
    `id`            bigint UNSIGNED NOT NULL COMMENT '主键',
    `category_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '分类名称',
    `sort_no`       int NULL DEFAULT 0 COMMENT '排序',
    `created`       datetime                                                     NOT NULL COMMENT '创建时间',
    `created_by`    bigint UNSIGNED NOT NULL COMMENT '创建者',
    `modified`      datetime                                                     NOT NULL COMMENT '修改时间',
    `modified_by`   bigint UNSIGNED NOT NULL COMMENT '修改者',
    `status`        int                                                          NOT NULL DEFAULT 0 COMMENT '数据状态',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '素材分类' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for tb_sys_account
-- ----------------------------
CREATE TABLE `tb_sys_account`
(
    `id`                     bigint UNSIGNED NOT NULL COMMENT '主键',
    `dept_id`                bigint UNSIGNED NOT NULL COMMENT '部门ID',
    `tenant_id`              bigint UNSIGNED NOT NULL COMMENT '租户ID',
    `login_name`             varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '登录账号',
    `password`               varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '密码',
    `password_reset_required` tinyint                                              NOT NULL DEFAULT 0 COMMENT '是否需要重置密码',
    `account_type`           tinyint NOT NULL DEFAULT 0 COMMENT '账户类型',
    `nickname`               varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT '' COMMENT '昵称',
    `mobile`                 varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT '' COMMENT '手机电话',
    `email`                  varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT '' COMMENT '邮件',
    `avatar`                 varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT '' COMMENT '账户头像',
    `status`                 int NOT NULL DEFAULT 0 COMMENT '数据状态',
    `created`                datetime NOT NULL COMMENT '创建时间',
    `created_by`             bigint UNSIGNED NOT NULL COMMENT '创建者',
    `modified`               datetime NOT NULL COMMENT '修改时间',
    `modified_by`            bigint UNSIGNED NOT NULL COMMENT '修改者',
    `remark`                 varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT '' COMMENT '备注',
    `is_deleted`             tinyint NOT NULL DEFAULT 0 COMMENT '逻辑删除标识：0未删除，1已删除',
    PRIMARY KEY (`id`) USING BTREE,
    INDEX `idx_login_name`(`login_name`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '用户表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_sys_account_position
-- ----------------------------
CREATE TABLE `tb_sys_account_position`
(
    `id`          bigint UNSIGNED NOT NULL COMMENT '主键',
    `account_id`  bigint UNSIGNED NOT NULL COMMENT '用户ID',
    `position_id` bigint UNSIGNED NOT NULL COMMENT '职位ID',
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE INDEX `uni_account_position`(`account_id`, `position_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '用户-职位表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_sys_account_role
-- ----------------------------
CREATE TABLE `tb_sys_account_role`
(
    `id`         bigint UNSIGNED NOT NULL COMMENT '主键',
    `account_id` bigint UNSIGNED NOT NULL COMMENT '用户ID',
    `role_id`    bigint UNSIGNED NOT NULL COMMENT '角色ID',
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE INDEX `uni_account_role`(`account_id`, `role_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '用户-角色表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_sys_api_key
-- ----------------------------
CREATE TABLE `tb_sys_api_key`
(
    `id`         bigint UNSIGNED NOT NULL COMMENT 'id',
    `api_key`    varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'apiKey',
    `created`    datetime NULL DEFAULT NULL COMMENT '创建时间',
    `status`     int NOT NULL DEFAULT 0 COMMENT '数据状态',
    `dept_id`    bigint UNSIGNED NULL DEFAULT NULL COMMENT '部门id',
    `tenant_id`  bigint UNSIGNED NULL DEFAULT NULL COMMENT '租户id',
    `expired_at` datetime NULL DEFAULT NULL COMMENT '失效时间',
    `created_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建人',
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE INDEX `uni_api_key`(`api_key`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = 'apikey表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_sys_api_key_resource
-- ----------------------------
CREATE TABLE `tb_sys_api_key_resource`
(
    `id`                bigint UNSIGNED NOT NULL COMMENT 'id',
    `request_interface` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '请求接口',
    `title`             varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '标题',
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE KEY `uni_api` (`request_interface`)
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '请求接口表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for tb_sys_api_key_resource_mapping
-- ----------------------------
CREATE TABLE `tb_sys_api_key_resource_mapping`
(
    `id`                  bigint UNSIGNED NOT NULL COMMENT 'id',
    `api_key_id`          bigint UNSIGNED NOT NULL COMMENT 'api_key_id',
    `api_key_resource_id` bigint UNSIGNED NOT NULL COMMENT '请求接口资源访问id',
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE INDEX `uni_api_key_resource`(`api_key_id`, `api_key_resource_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = 'apikey-请求接口表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for tb_sys_dept
-- ----------------------------
CREATE TABLE `tb_sys_dept`
(
    `id`          bigint UNSIGNED NOT NULL COMMENT '主键',
    `tenant_id`   bigint UNSIGNED NOT NULL COMMENT '租户ID',
    `parent_id`   bigint UNSIGNED NOT NULL COMMENT '父级ID',
    `ancestors`   varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT '' COMMENT '父级部门ID集合',
    `dept_name`   varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '部门名称',
    `dept_code`   varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT '' COMMENT '部门编码',
    `sort_no`     int NULL DEFAULT 0 COMMENT '排序',
    `status`      int                                                           NOT NULL DEFAULT 0 COMMENT '数据状态',
    `created`     datetime                                                      NOT NULL COMMENT '创建时间',
    `created_by`  bigint UNSIGNED NOT NULL COMMENT '创建者',
    `modified`    datetime                                                      NOT NULL COMMENT '修改时间',
    `modified_by` bigint UNSIGNED NOT NULL COMMENT '修改者',
    `remark`      varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT '' COMMENT '备注',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '部门表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_sys_dict
-- ----------------------------
CREATE TABLE `tb_sys_dict`
(
    `id`          bigint UNSIGNED NOT NULL COMMENT '主键',
    `name`        varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '数据字典名称',
    `code`        varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '' COMMENT '字典编码',
    `description` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '字典描述或备注',
    `dict_type`   tinyint NULL DEFAULT NULL COMMENT '字典类型 1 自定义字典、2 数据表字典、 3 枚举类字典、 4 系统字典（自定义 DictLoader）',
    `sort_no`     int NULL DEFAULT NULL COMMENT '排序编号',
    `status`      int                                                          NOT NULL DEFAULT 0 COMMENT '数据状态',
    `options`     text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '扩展字典  存放 json',
    `created`     datetime NULL DEFAULT NULL COMMENT '创建时间',
    `modified`    datetime NULL DEFAULT NULL COMMENT '修改时间',
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE INDEX `key`(`code`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '系统字典表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_sys_dict_item
-- ----------------------------
CREATE TABLE `tb_sys_dict_item`
(
    `id`          bigint UNSIGNED NOT NULL COMMENT '主键',
    `dict_id`     bigint UNSIGNED NOT NULL COMMENT '归属哪个字典',
    `text`        varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '' COMMENT '名称或内容',
    `value`       varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '' COMMENT '值',
    `description` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '描述',
    `sort_no`     int                                                          NOT NULL DEFAULT 0 COMMENT '排序',
    `css_content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT 'css样式内容',
    `css_class`   varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'css样式类名',
    `remark`      varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '备注',
    `status`      int                                                          NOT NULL DEFAULT 0 COMMENT '数据状态',
    `created`     datetime NULL DEFAULT NULL COMMENT '创建时间',
    `modified`    datetime NULL DEFAULT NULL COMMENT '修改时间',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '数据字典内容' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_sys_job
-- ----------------------------
CREATE TABLE `tb_sys_job`
(
    `id`               bigint UNSIGNED NOT NULL COMMENT '主键',
    `dept_id`          bigint UNSIGNED NOT NULL COMMENT '部门ID',
    `tenant_id`        bigint UNSIGNED NOT NULL COMMENT '租户ID',
    `job_name`         varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '任务名称',
    `job_type`         int                                                           NOT NULL COMMENT '任务类型',
    `job_params`       text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '任务参数',
    `cron_expression`  varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci  NOT NULL COMMENT 'cron表达式',
    `allow_concurrent` int                                                           NOT NULL DEFAULT 0 COMMENT '是否并发执行',
    `misfire_policy`   int                                                           NOT NULL DEFAULT 3 COMMENT '错过策略',
    `options`          text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '其他配置',
    `status`           int                                                           NOT NULL DEFAULT 0 COMMENT '数据状态',
    `created`          datetime                                                      NOT NULL COMMENT '创建时间',
    `created_by`       bigint UNSIGNED NOT NULL COMMENT '创建者',
    `modified`         datetime                                                      NOT NULL COMMENT '修改时间',
    `modified_by`      bigint UNSIGNED NOT NULL COMMENT '修改者',
    `remark`           varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT '' COMMENT '备注',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '系统任务表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_sys_job_log
-- ----------------------------
CREATE TABLE `tb_sys_job_log`
(
    `id`         bigint UNSIGNED NOT NULL COMMENT '主键',
    `job_id`     bigint UNSIGNED NOT NULL COMMENT '任务ID',
    `job_name`   varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '任务名称',
    `job_params` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '任务参数',
    `job_result` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '执行结果',
    `error_info` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '错误信息',
    `status`     int                                                           NOT NULL DEFAULT 0 COMMENT '数据状态',
    `start_time` datetime                                                      NOT NULL COMMENT '开始时间',
    `end_time`   datetime                                                      NOT NULL COMMENT '结束时间',
    `created`    datetime                                                      NOT NULL COMMENT '创建时间',
    `remark`     varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT '' COMMENT '备注',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '系统任务日志' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_sys_log
-- ----------------------------
CREATE TABLE `tb_sys_log`
(
    `id`            bigint UNSIGNED NOT NULL COMMENT 'ID',
    `account_id`    bigint UNSIGNED NULL DEFAULT NULL COMMENT '操作人',
    `action_name`   varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '操作名称',
    `action_type`   varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '操作的类型',
    `action_class`  varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '操作涉及的类',
    `action_method` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '操作涉及的方法',
    `action_url`    varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '操作涉及的 URL 地址',
    `action_ip`     varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '操作涉及的用户 IP 地址',
    `action_params` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '操作请求参数',
    `action_body`   text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '操作请求body',
    `status`        int NOT NULL DEFAULT 0 COMMENT '数据状态',
    `created`       datetime NULL DEFAULT NULL COMMENT '操作时间',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '操作日志表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_sys_menu
-- ----------------------------
CREATE TABLE `tb_sys_menu`
(
    `id`             bigint UNSIGNED NOT NULL COMMENT '主键',
    `parent_id`      bigint UNSIGNED NOT NULL COMMENT '父菜单id',
    `menu_type`      int                                                           NOT NULL COMMENT '菜单类型',
    `menu_title`     varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '菜单标题',
    `menu_url`       varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT '' COMMENT '菜单url',
    `component`      varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT '' COMMENT '组件路径',
    `menu_icon`      varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT '' COMMENT '图标/图片地址',
    `is_show`        int                                                           NOT NULL DEFAULT 1 COMMENT '是否显示',
    `permission_tag` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT '' COMMENT '权限标识',
    `sort_no`        int NULL DEFAULT 0 COMMENT '排序',
    `status`         int                                                           NOT NULL DEFAULT 0 COMMENT '数据状态',
    `created`        datetime                                                      NOT NULL COMMENT '创建时间',
    `created_by`     bigint UNSIGNED NOT NULL COMMENT '创建者',
    `modified`       datetime                                                      NOT NULL COMMENT '修改时间',
    `modified_by`    bigint UNSIGNED NOT NULL COMMENT '修改者',
    `remark`         varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT '' COMMENT '备注',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '菜单表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_sys_option
-- ----------------------------
CREATE TABLE `tb_sys_option`
(
    `tenant_id` bigint UNSIGNED NOT NULL COMMENT '租户ID',
    `key`       varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '配置KEY',
    `value`     text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '配置内容',
    UNIQUE INDEX `uni_key`(`tenant_id`, `key`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '系统配置信息表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_sys_position
-- ----------------------------
CREATE TABLE `tb_sys_position`
(
    `id`            bigint UNSIGNED NOT NULL COMMENT '主键',
    `tenant_id`     bigint UNSIGNED NOT NULL COMMENT '租户ID',
    `dept_id`       bigint UNSIGNED NOT NULL COMMENT '部门ID',
    `position_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '岗位名称',
    `position_code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT '' COMMENT '岗位编码',
    `sort_no`       int NULL DEFAULT 0 COMMENT '排序',
    `status`        int                                                          NOT NULL DEFAULT 0 COMMENT '数据状态',
    `created`       datetime                                                     NOT NULL COMMENT '创建时间',
    `created_by`    bigint UNSIGNED NOT NULL COMMENT '创建者',
    `modified`      datetime                                                     NOT NULL COMMENT '修改时间',
    `modified_by`   bigint UNSIGNED NOT NULL COMMENT '修改者',
    `remark`        varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT '' COMMENT '备注',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '职位表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_sys_role
-- ----------------------------
CREATE TABLE `tb_sys_role`
(
    `id`                  bigint UNSIGNED NOT NULL COMMENT '主键',
    `tenant_id`           bigint UNSIGNED NOT NULL COMMENT '租户ID',
    `role_name`           varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '角色名称',
    `role_key`            varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '角色标识',
    `status`              int                                                          NOT NULL DEFAULT 0 COMMENT '数据状态',
    `created`             datetime                                                     NOT NULL COMMENT '创建时间',
    `created_by`          bigint UNSIGNED NOT NULL COMMENT '创建者',
    `modified`            datetime                                                     NOT NULL COMMENT '修改时间',
    `modified_by`         bigint UNSIGNED NOT NULL COMMENT '修改者',
    `remark`              varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT '' COMMENT '备注',
    `data_scope`          int NULL DEFAULT 1 COMMENT '数据权限(EnumDataScope)',
    `menu_check_strictly` tinyint NULL DEFAULT 1 COMMENT '菜单树选择项是否关联显示',
    `dept_check_strictly` tinyint NULL DEFAULT 1 COMMENT '部门树选择项是否关联显示',
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE INDEX `uni_tenant_role`(`tenant_id`, `role_key`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '系统角色' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_sys_role_dept
-- ----------------------------
CREATE TABLE `tb_sys_role_dept`
(
    `id`      bigint UNSIGNED NOT NULL COMMENT '主键',
    `role_id` bigint UNSIGNED NOT NULL COMMENT '角色ID',
    `dept_id` bigint UNSIGNED NOT NULL COMMENT '部门ID',
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE INDEX `uni_role_dept`(`role_id`, `dept_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '角色-部门表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_sys_role_menu
-- ----------------------------
CREATE TABLE `tb_sys_role_menu`
(
    `id`      bigint UNSIGNED NOT NULL COMMENT '主键',
    `role_id` bigint UNSIGNED NOT NULL COMMENT '角色ID',
    `menu_id` bigint UNSIGNED NOT NULL COMMENT '菜单ID',
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE INDEX `uni_role_menu`(`role_id`, `menu_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '角色-菜单表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_workflow
-- ----------------------------
CREATE TABLE `tb_workflow`
(
    `id`           bigint UNSIGNED NOT NULL COMMENT 'ID 主键',
    `alias`        varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '别名',
    `dept_id`      bigint UNSIGNED NOT NULL COMMENT '部门ID',
    `tenant_id`    bigint UNSIGNED NOT NULL COMMENT '租户ID',
    `title`        varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '标题',
    `description`  varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '描述',
    `icon`         varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'ICON',
    `content`      text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '工作流设计的 JSON 内容',
    `created`      datetime NULL DEFAULT NULL COMMENT '创建时间',
    `created_by`   bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建人',
    `modified`     datetime NULL DEFAULT NULL COMMENT '最后修改时间',
    `modified_by`  bigint UNSIGNED NULL DEFAULT NULL COMMENT '最后修改的人',
    `english_name` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '英文名称',
    `status`       int                                                           NOT NULL DEFAULT 0 COMMENT '数据状态',
    `category_id`  bigint UNSIGNED NULL DEFAULT NULL COMMENT '分类ID',
    `visibility_scope` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '可见范围',
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE INDEX `tb_ai_workflow_alias_uindex`(`alias`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '工作流' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_workflow_category
-- ----------------------------
CREATE TABLE `tb_workflow_category`
(
    `id`            bigint UNSIGNED NOT NULL COMMENT '主键',
    `category_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '分类名称',
    `sort_no`       int NULL DEFAULT 0 COMMENT '排序',
    `created`       datetime                                                     NOT NULL COMMENT '创建时间',
    `created_by`    bigint UNSIGNED NOT NULL COMMENT '创建者',
    `modified`      datetime                                                     NOT NULL COMMENT '修改时间',
    `modified_by`   bigint UNSIGNED NOT NULL COMMENT '修改者',
    `status`        int                                                          NOT NULL DEFAULT 0 COMMENT '数据状态',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '工作流分类' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for tb_workflow_exec_result
-- ----------------------------
CREATE TABLE `tb_workflow_exec_result`
(
    `id`            bigint UNSIGNED NOT NULL COMMENT '主键',
    `exec_key`      varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '执行标识',
    `workflow_id`   bigint UNSIGNED NOT NULL COMMENT '工作流ID',
    `title`         varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '标题',
    `description`   varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '描述',
    `input`         text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '输入',
    `output`        text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '输出',
    `workflow_json` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '工作流执行时的配置',
    `start_time`    datetime(3) NOT NULL COMMENT '开始时间',
    `end_time`      datetime(3) NULL DEFAULT NULL COMMENT '结束时间',
    `tokens`        bigint UNSIGNED NULL DEFAULT NULL COMMENT '消耗总token',
    `status`        int                                                           NOT NULL DEFAULT 0 COMMENT '数据状态',
    `created_key`   varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '执行人标识[有可能是用户|外部|定时任务等情况]',
    `created_by`    varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '执行人',
    `error_info`    text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '错误信息',
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE INDEX `uni_exec_key`(`exec_key`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '工作流执行记录' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_workflow_exec_step
-- ----------------------------
CREATE TABLE `tb_workflow_exec_step`
(
    `id`         bigint UNSIGNED NOT NULL COMMENT '主键',
    `record_id`  bigint UNSIGNED NOT NULL COMMENT '执行记录ID',
    `exec_key`   varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '执行标识',
    `node_id`    varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '节点ID',
    `node_name`  varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci  NOT NULL COMMENT '节点名称',
    `input`      longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '输入',
    `output`     longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '输出',
    `node_data`  text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '节点信息',
    `start_time` datetime(3) NOT NULL COMMENT '开始时间',
    `end_time`   datetime(3) NULL DEFAULT NULL COMMENT '结束时间',
    `tokens`     bigint UNSIGNED NULL DEFAULT NULL COMMENT '消耗总token',
    `status`     int                                                           NOT NULL DEFAULT 0 COMMENT '数据状态',
    `error_info` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '错误信息',
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE INDEX `uni_exec`(`exec_key`) USING BTREE,
    INDEX        `idx_record_id`(`record_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '执行记录步骤' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_sys_user_feedback
-- ----------------------------
CREATE TABLE `tb_sys_user_feedback`
(
    `id`               bigint UNSIGNED NOT NULL COMMENT '主键id',
    `feedback_content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '问题摘要',
    `feedback_type`    int NOT NULL COMMENT '问题类型（1-功能故障 2-优化建议 3-账号问题 4-其他）',
    `contact_info`     varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '联系方式【手机号/邮箱】',
    `attachment_url`   text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '附件url',
    `status`           int NULL DEFAULT NULL COMMENT '反馈处理状态（0-未查看 1-已查看 2-已处理）',
    `handler_id`       bigint UNSIGNED NULL DEFAULT NULL COMMENT '处理人id',
    `handle_time`      datetime NULL DEFAULT NULL COMMENT '处理时间',
    `dept_id`          bigint UNSIGNED NOT NULL COMMENT '部门ID',
    `tenant_id`        bigint UNSIGNED NOT NULL COMMENT '租户ID',
    `created`          datetime NOT NULL COMMENT '创建时间',
    `created_by`       bigint UNSIGNED NOT NULL COMMENT '创建人',
    `modified`         datetime NULL DEFAULT NULL COMMENT '最后修改时间',
    `modified_by`      bigint UNSIGNED NULL DEFAULT NULL COMMENT '最后修改的人',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for tb_mcp
-- ----------------------------
CREATE TABLE `tb_mcp`
(
    `id`          bigint UNSIGNED NOT NULL COMMENT 'id',
    `title`       varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '标题',
    `description` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '描述',
    `config_json` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '完整MCP配置JSON',
    `dept_id`     bigint UNSIGNED NOT NULL COMMENT '部门ID',
    `tenant_id`   bigint UNSIGNED NOT NULL COMMENT '租户ID',
    `created`     datetime NULL DEFAULT NULL COMMENT '创建时间',
    `created_by`  bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建者ID',
    `modified`    datetime NULL DEFAULT NULL COMMENT '修改时间',
    `modified_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '修改者ID',
    `status`      tinyint NULL DEFAULT 0 COMMENT '是否启用',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = 'mcp表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for tb_bot_mcp
-- ----------------------------
CREATE TABLE `tb_bot_mcp`
(
    `id`                   bigint UNSIGNED NOT NULL COMMENT 'id',
    `bot_id`               bigint UNSIGNED NULL DEFAULT NULL COMMENT 'botId',
    `mcp_id`               bigint UNSIGNED NULL DEFAULT NULL COMMENT 'mcpId',
    `mcp_tool_name`        varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'mcp工具名称',
    `mcp_tool_description` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'mcp工具描述',
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE INDEX `uni_bot_mcp`(`bot_id`, `mcp_id`, `mcp_tool_name`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;

CREATE TABLE `tb_sys_role_category_scope`
(
    `id`            bigint UNSIGNED NOT NULL COMMENT '主键',
    `role_id`       bigint UNSIGNED NOT NULL COMMENT '角色ID',
    `resource_type` varchar(32) NOT NULL COMMENT '资源类型',
    `scope_mode`    varchar(16) NOT NULL COMMENT '范围模式',
    `created`       datetime NULL DEFAULT NULL COMMENT '创建时间',
    `created_by`    bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建者',
    `modified`      datetime NULL DEFAULT NULL COMMENT '修改时间',
    `modified_by`   bigint UNSIGNED NULL DEFAULT NULL COMMENT '修改者',
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE INDEX `uni_role_resource_type`(`role_id`, `resource_type`) USING BTREE
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '角色分类权限范围';

CREATE TABLE `tb_sys_role_category_scope_item`
(
    `id`          bigint UNSIGNED NOT NULL COMMENT '主键',
    `scope_id`    bigint UNSIGNED NOT NULL COMMENT '范围ID',
    `category_id` bigint UNSIGNED NOT NULL COMMENT '分类ID',
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE INDEX `uni_scope_category`(`scope_id`, `category_id`) USING BTREE
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '角色分类权限明细';

CREATE TABLE `tb_datacenter_source`
(
    `id`                 bigint UNSIGNED NOT NULL COMMENT '主键',
    `dept_id`            bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '部门ID',
    `tenant_id`          bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '租户ID',
    `source_name`        varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '数据源名称',
    `source_code`        varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '数据源编码',
    `source_type`        varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '数据源类型',
    `access_mode`        varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT 'READ_ONLY' COMMENT '访问模式',
    `builtin_flag`       int NOT NULL DEFAULT 0 COMMENT '是否内置',
    `driver_class_name`  varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '驱动类名',
    `jdbc_url`           varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'JDBC URL',
    `host`               varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '主机',
    `port`               int NULL DEFAULT NULL COMMENT '端口',
    `database_name`      varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '数据库名',
    `schema_name`        varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'Schema名',
    `username`           varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '用户名',
    `credential_cipher`  text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '凭据密文',
    `config_json`        text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '连接配置',
    `capabilities_json`  text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '能力声明',
    `last_test_status`   varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '最近测试状态',
    `last_test_message`  varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '最近测试信息',
    `last_tested_at`     datetime NULL DEFAULT NULL COMMENT '最近测试时间',
    `status`             int NOT NULL DEFAULT 0 COMMENT '状态',
    `options`            text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '扩展项',
    `created`            datetime NOT NULL COMMENT '创建时间',
    `created_by`         bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '创建人',
    `modified`           datetime NOT NULL COMMENT '修改时间',
    `modified_by`        bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '修改人',
    PRIMARY KEY (`id`) USING BTREE,
    KEY `idx_datacenter_source_tenant_type` (`tenant_id`, `source_type`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '数据中心数据源' ROW_FORMAT = DYNAMIC;

CREATE TABLE `tb_datacenter_catalog`
(
    `id`                bigint UNSIGNED NOT NULL COMMENT '主键',
    `dept_id`           bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '部门ID',
    `tenant_id`         bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '租户ID',
    `source_id`         bigint UNSIGNED NOT NULL COMMENT '数据源ID',
    `catalog_name`      varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '目录名',
    `catalog_desc`      varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '目录描述',
    `catalog_type`      varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT 'DATABASE' COMMENT '目录类型',
    `status`            int NOT NULL DEFAULT 0 COMMENT '状态',
    `options`           text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '扩展项',
    `created`           datetime NOT NULL COMMENT '创建时间',
    `created_by`        bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '创建人',
    `modified`          datetime NOT NULL COMMENT '修改时间',
    `modified_by`       bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '修改人',
    PRIMARY KEY (`id`) USING BTREE,
    KEY `idx_datacenter_catalog_source` (`source_id`, `catalog_name`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '数据中心逻辑库/命名空间' ROW_FORMAT = DYNAMIC;

CREATE TABLE `tb_datacenter_dataset_version`
(
    `id`                 bigint UNSIGNED NOT NULL COMMENT '主键',
    `dept_id`            bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '部门ID',
    `tenant_id`          bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '租户ID',
    `table_id`           bigint UNSIGNED NOT NULL COMMENT '表ID',
    `version_no`         int NOT NULL DEFAULT 1 COMMENT '版本号',
    `version_label`      varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '版本标签',
    `materialized_table` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '物化表名',
    `snapshot_json`      text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '版本快照',
    `status`             int NOT NULL DEFAULT 0 COMMENT '状态',
    `created`            datetime NOT NULL COMMENT '创建时间',
    `created_by`         bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '创建人',
    `modified`           datetime NOT NULL COMMENT '修改时间',
    `modified_by`        bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '修改人',
    PRIMARY KEY (`id`) USING BTREE,
    KEY `idx_dataset_version_table` (`table_id`, `version_no`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '数据集版本' ROW_FORMAT = DYNAMIC;

CREATE TABLE `tb_datacenter_import_job`
(
    `id`            bigint UNSIGNED NOT NULL COMMENT '主键',
    `dept_id`       bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '部门ID',
    `tenant_id`     bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '租户ID',
    `source_id`     bigint UNSIGNED NULL DEFAULT NULL COMMENT '数据源ID',
    `catalog_id`    bigint UNSIGNED NULL DEFAULT NULL COMMENT '目录ID',
    `table_id`      bigint UNSIGNED NULL DEFAULT NULL COMMENT '表ID',
    `job_type`      varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '任务类型',
    `file_name`     varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '文件名',
    `storage_path`  varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '文件存储路径',
    `status`        varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '任务状态',
    `total_rows`    bigint NULL DEFAULT NULL COMMENT '总行数',
    `success_rows`  bigint NULL DEFAULT NULL COMMENT '成功行数',
    `error_rows`    bigint NULL DEFAULT NULL COMMENT '失败行数',
    `error_summary` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '错误摘要',
    `payload_json`  longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '任务载荷',
    `started_at`    datetime NULL DEFAULT NULL COMMENT '开始时间',
    `finished_at`   datetime NULL DEFAULT NULL COMMENT '结束时间',
    `created`       datetime NOT NULL COMMENT '创建时间',
    `created_by`    bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '创建人',
    `modified`      datetime NOT NULL COMMENT '修改时间',
    `modified_by`   bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '修改人',
    PRIMARY KEY (`id`) USING BTREE,
    KEY `idx_import_job_source` (`source_id`, `status`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '数据中心导入任务' ROW_FORMAT = DYNAMIC;

CREATE TABLE `tb_datacenter_derived_table`
(
    `id`                 bigint UNSIGNED NOT NULL COMMENT '主键',
    `dept_id`            bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '部门ID',
    `tenant_id`          bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '租户ID',
    `source_table_id`    bigint UNSIGNED NOT NULL COMMENT '源表ID',
    `derived_table_id`   bigint UNSIGNED NOT NULL COMMENT '派生表ID',
    `derive_type`        varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '派生类型',
    `derive_config_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '派生配置',
    `status`             int NOT NULL DEFAULT 0 COMMENT '状态',
    `created`            datetime NOT NULL COMMENT '创建时间',
    `created_by`         bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '创建人',
    `modified`           datetime NOT NULL COMMENT '修改时间',
    `modified_by`        bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '修改人',
    PRIMARY KEY (`id`) USING BTREE,
    KEY `idx_derived_table_source` (`source_table_id`, `derived_table_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '数据中心派生表关系' ROW_FORMAT = DYNAMIC;

SET
FOREIGN_KEY_CHECKS = 1;
