拓冰建站拓冰建站
首页 / 资讯中心 / 正文

DB-GPT v0.6.0 升级指南:从 v0.5.10 平滑迁移的完整 MySQL 数据库升级方案

DB-GPT v0.6.0 升级指南从 v0.5.10 平滑迁移的完整 MySQL 数据库升级方案【免费下载链接】DB-GPTopen-source agentic AI data assistant for the next generation of AI Data products.项目地址: https://gitcode.com/GitHub_Trending/db/DB-GPTDB-GPT 在 v0.6.0 版本中引入了一系列面向 Agent 应用、推荐问题、用户近期使用记录、文件存储与变量管理等新能力这些能力依赖数据库结构的扩展。本文基于官方升级文档docs/i18n/zh-CN/docusaurus-plugin-content-docs/current/upgrade/v0.6.0.md完整讲解从 v0.5.10 升级到 v0.6.0 时 MySQL 数据库的迁移步骤、全部 SQL 变更明细并深入仓库源码逐一印证每个新字段和新表的实际用途帮助你安全、准确地完成升级并理解新版本的数据模型。升级概览与前置准备v0.6.0 升级指南的适用范围非常明确升级路径从v0.5.10升级到v0.6.0若使用SQLite无需升级数据库若使用MySQL必须执行数据库升级脚本。升级前建议根据你的数据库类型对现有数据库进行完整备份以防数据丢失。官方为每次版本升级维护了独立的 SQL 资产目录v0.6.0 对应的升级脚本与基线脚本位于 assets/schema/upgrade/v0_6_0/ 目录upgrade_to_v0.6.0.sql从 v0.5.10 升级到 v0.6.0 的增量变更脚本与本文档内容一致可直接复用v0.5.10.sqlv0.5.10 版本的完整建表基线用于对照升级前的库结构文件中明确注明“请勿修改必须与 release 包中的文件保持一致”。升级资产目录统一按assets/schema/upgrade/vX_Y_Z/组织每个版本目录下都同时存放“上一版本全量基线”和“升级增量脚本”两类文件便于审计与回滚。升级操作步骤第一步停止 DB-GPT 服务按照你实际启动 DB-GPT 的方式停止服务避免在升级过程中出现新的写入保证迁移期间数据一致。第二步执行数据库升级 SQL在 MySQL 客户端中按顺序执行升级脚本或直接执行assets/schema/upgrade/v0_6_0/upgrade_to_v0.6.0.sqlUSE dbgpt;下面的变更可归纳为两类存量表扩展新字段ALTER TABLE与新建业务表CREATE TABLE。存量表的字段扩展ALTER TABLEv0.6.0 对 9 张存量表进行了字段扩展每一处变更都对应一个新版本中的具体业务能力。chat_history对话记录与应用关联-- chat_history ALTER TABLE chat_history ADD COLUMN app_code varchar(255) DEFAULT NULL COMMENT App unique code after message_ids;该字段将对话历史与某个具体的 AI 应用Agent App绑定。在 packages/dbgpt-core/src/dbgpt/storage/chat_history/chat_history_db.py 中ChatHistoryEntity定义了app_code列并为其建立了idx_chat_his_app_code索引。同一文件中的get_hot_app_map逻辑会基于app_code对已发布的应用进行分组计数Select COUNT(*) as sz, app_code from chat_history where app_code in (select app_code from gpts_app where ...) group by app_code order by sz desc由此可见app_code是 v0.6.0 “热门应用排行” 与 “按应用维度统计对话” 功能的数据基础。gpts_app应用发布与协作控制-- gpts_app ALTER TABLE gpts_app ADD COLUMN published varchar(64) DEFAULT false COMMENT Has it been published?; ALTER TABLE gpts_app ADD COLUMN param_need text DEFAULT NULL COMMENT Parameter information supported by the application; ALTER TABLE gpts_app ADD COLUMN admins text DEFAULT NULL COMMENT administrator;published标记应用是否已发布。在 packages/dbgpt-serve/src/dbgpt_serve/agent/db/gpts_app.py 中对应GptsAppEntity.published字段应用列表查询会通过GptsAppEntity.published query.published.lower()做过滤创建应用时统一落为true或falsepublishedtrue if gpts_app.published else false。param_need应用对外暴露的参数信息JSON 文本。代码中_entity_to_app_dict通过json.loads(app_info.param_need)解析后随应用详情返回给前端。admins应用管理员列表。查询逻辑中会使用GptsAppEntity.admins.like(f%{query.user_code}%)让管理员也能看到自己管理的应用。connect_config连接配置归属-- connect_config ALTER TABLE connect_config ADD COLUMN user_name varchar(255) DEFAULT NULL COMMENT user name; ALTER TABLE connect_config ADD COLUMN user_id varchar(255) DEFAULT NULL COMMENT user id;为数据源连接配置增加用户归属信息使连接数据源可以被记录创建者支撑多用户场景下的连接管理与权限隔离。document_chunk 与 knowledge_document知识库推荐问题-- document_chunk ALTER TABLE document_chunk ADD COLUMN questions text DEFAULT NULL COMMENT chunk related questions; -- knowledge_document ALTER TABLE knowledge_document ADD COLUMN doc_token varchar(100) DEFAULT NULL COMMENT doc token; ALTER TABLE knowledge_document ADD COLUMN questions text DEFAULT NULL COMMENT document related questions;questions为文档块 / 文档记录关联的“推荐问题”文本支撑知识库的问答推荐与召回doc_token文档的访问令牌用于知识库文档的鉴权访问。gpts_messagesAgent 消息结果与资源信息-- gpts_messages ALTER TABLE gpts_messages ADD COLUMN is_success int(4) NULL DEFAULT 0 COMMENT agent message is success; ALTER TABLE gpts_messages ADD COLUMN app_code varchar(255) NOT NULL COMMENT Current AI assistant code; ALTER TABLE gpts_messages ADD COLUMN app_name varchar(255) NOT NULL COMMENT Current AI assistant name; ALTER TABLE gpts_messages ADD COLUMN resource_info text DEFAULT NULL COMMENT Current conversation resource info;is_successAgent 消息处理是否成功默认 0用于在对话界面标注 Agent 调用结果状态app_code/app_name记录该条 Agent 消息所属的 AI 助手及其名称将消息与具体应用绑定resource_info当前会话所使用资源的 JSON 描述用于会话的资源展示与审计。prompt_manage提示词管理与响应约束-- prompt_manage ALTER TABLE prompt_manage ADD COLUMN prompt_code varchar(255) NULL COMMENT Prompt code; ALTER TABLE prompt_manage ADD COLUMN response_schema text NULL COMMENT Prompt response schema; ALTER TABLE prompt_manage ADD COLUMN user_code varchar(128) NULL COMMENT User code;prompt_code提示词的全局唯一编码便于按编码引用而非仅按名称response_schema提示词期望的响应结构如 JSON Schema用于约束模型结构化输出user_code提示词的创建者编码支撑私有提示词。chat_feed_back结构化反馈-- chat_feed_back ALTER TABLE chat_feed_back ADD COLUMN message_id varchar(255) NULL COMMENT Message id; ALTER TABLE chat_feed_back ADD COLUMN feedback_type varchar(50) NULL COMMENT Feedback type like or unlike; ALTER TABLE chat_feed_back ADD COLUMN reason_types varchar(255) NULL COMMENT Feedback reason categories; ALTER TABLE chat_feed_back ADD COLUMN user_code varchar(128) NULL COMMENT User code; ALTER TABLE chat_feed_back ADD COLUMN remark text NULL COMMENT Feedback remark;将反馈表从单一的评分扩展为结构化反馈message_id精确定位被反馈的消息feedback_type记录赞 / 踩like or unlikereason_types记录原因分类remark记录补充说明为评估与调优提供更细粒度的数据。dbgpt_serve_flow工作流变量-- dbgpt_serve_flow ALTER TABLE dbgpt_serve_flow ADD COLUMN variables text DEFAULT NULL COMMENT Flow variables, JSON format;为 AWEL 工作流Flow增加变量存储字段JSON 格式。在 v0.6.0 中变量被抽离为独立的变量服务详见下文dbgpt_serve_variables表该字段用于工作流维度的变量上下文。新建业务表CREATE TABLEv0.6.0 新增 6 张表分别支撑推荐问题、近期使用、文件存储、变量管理、已安装插件与插件市场。recommend_questionAI 应用推荐问题-- dbgpt.recommend_question definition CREATE TABLE recommend_question ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT autoincrement id, gmt_create timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT create time, gmt_modified timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT last update time, app_code varchar(255) DEFAULT NULL COMMENT Current AI assistant code, question text DEFAULT NULL COMMENT question, user_code int(11) DEFAULT NULL COMMENT user code, sys_code varchar(255) DEFAULT NULL COMMENT system app code, valid varchar(10) DEFAULT true COMMENT is it effectivetrue/false, chat_mode varchar(255) DEFAULT NULL COMMENT Conversation scene modechat_knowledge..., params text DEFAULT NULL COMMENT question param, is_hot_question varchar(10) DEFAULT false COMMENT Is it a popular recommendation question?, PRIMARY KEY (id), KEY idx_rec_q_app_code (app_code) ) ENGINEInnoDB AUTO_INCREMENT1 DEFAULT CHARSETutf8mb4 COLLATEutf8mb4_unicode_ci COMMENTAI application related recommendation issues;该表用于存储每个 AI 应用的推荐提问让用户在进入应用时可以直接点击预设问题发起对话。对应的 ORM 实体与 DAO 位于 packages/dbgpt-serve/src/dbgpt_serve/agent/app/recommend_question/recommend_question.pyRecommendQuestionEntity映射到recommend_question表包含question、valid、params、chat_mode、is_hot_question等字段RecommendQuestionDao提供list_questions支持按valid、app_code、chat_mode、is_hot_question过滤、create、update_question、delete_question、delete_by_app_code等完整 CRUD。字段说明字段类型说明app_codevarchar(255)关联的 AI 应用编码questiontext推荐问题内容validvarchar(10)是否有效true/falsechat_modevarchar(255)会话场景模式如chat_knowledgeparamstext问题携带的参数JSONis_hot_questionvarchar(10)是否为热门推荐问题会展示在主页面在应用创建 / 编辑逻辑中packages/dbgpt-serve/src/dbgpt_serve/agent/db/gpts_app.py应用携带的recommend_questions会被批量写入该表chat_mode会根据应用类型自动取ChatScene.ChatAgent或NativeTeamContext.chat_scene。user_recent_apps用户近期使用应用-- dbgpt.user_recent_apps definition CREATE TABLE user_recent_apps ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT autoincrement id, gmt_create timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT create time, gmt_modified timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT last update time, app_code varchar(255) DEFAULT NULL COMMENT AI assistant code, last_accessed timestamp NULL DEFAULT NULL COMMENT User recent usage time, user_code varchar(255) DEFAULT NULL COMMENT user code, sys_code varchar(255) DEFAULT NULL COMMENT system app code, PRIMARY KEY (id), KEY idx_user_r_app_code (app_code), KEY idx_last_accessed (last_accessed), KEY idx_user_code (user_code) ) ENGINEInnoDB AUTO_INCREMENT1 DEFAULT CHARSETutf8mb4 COLLATEutf8mb4_unicode_ci COMMENTUser recently used apps;记录用户最近访问的 AI 应用支撑“最近使用”列表。代码实现在 packages/dbgpt-serve/src/dbgpt_serve/agent/db/gpts_app.pyUserRecentAppsEntity映射该表并建立idx_user_r_app_code、idx_user_code、idx_last_accessed三个索引与 SQL 定义一致UserRecentAppsDao.query支持按user_code、sys_code、app_code过滤并按last_accessed倒序返回UserRecentAppsDao.upsert采用“存在则更新时间戳不存在则插入”的幂等写入策略在GptsAppDao.app_list中当查询参数is_recent_usedtrue时会先通过UserRecentAppsDao取近期应用编码再过滤应用列表。dbgpt_serve_file统一文件存储-- dbgpt.dbgpt_serve_file definition CREATE TABLE dbgpt_serve_file ( id int NOT NULL AUTO_INCREMENT COMMENT Auto increment id, bucket varchar(255) NOT NULL COMMENT Bucket name, file_id varchar(255) NOT NULL COMMENT File id, file_name varchar(256) NOT NULL COMMENT File name, file_size int DEFAULT NULL COMMENT File size, storage_type varchar(32) NOT NULL COMMENT Storage type, storage_path varchar(512) NOT NULL COMMENT Storage path, uri varchar(512) NOT NULL COMMENT File URI, custom_metadata text DEFAULT NULL COMMENT Custom metadata, JSON format, file_hash varchar(128) DEFAULT NULL COMMENT File hash, user_name varchar(128) DEFAULT NULL COMMENT User name, sys_code varchar(128) DEFAULT NULL COMMENT System code, gmt_created datetime DEFAULT CURRENT_TIMESTAMP COMMENT Record creation time, gmt_modified datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT Record update time, PRIMARY KEY (id), UNIQUE KEY uk_bucket_file_id (bucket, file_id) ) ENGINEInnoDB AUTO_INCREMENT1 DEFAULT CHARSETutf8mb4 COLLATEutf8mb4_unicode_ci;这是 v0.6.0 引入的统一文件存储服务dbgpt-serve/file的元数据表按(bucket, file_id)唯一约束管理文件对象。文件服务模块位于 packages/dbgpt-serve/src/dbgpt_serve/file/支持不同storage_type本地磁盘、对象存储等并通过storage_path、uri定位实际文件file_hash用于内容去重与完整性校验custom_metadata以 JSON 形式保存扩展属性。dbgpt_serve_variables全局变量管理-- dbgpt.dbgpt_serve_variables definition CREATE TABLE dbgpt_serve_variables ( id int NOT NULL AUTO_INCREMENT COMMENT Auto increment id, key varchar(128) NOT NULL COMMENT Variable key, name varchar(128) DEFAULT NULL COMMENT Variable name, label varchar(128) DEFAULT NULL COMMENT Variable label, value text DEFAULT NULL COMMENT Variable value, JSON format, value_type varchar(32) DEFAULT NULL COMMENT Variable value type(string, int, float, bool), category varchar(32) DEFAULT common COMMENT Variable category(common or secret), encryption_method varchar(32) DEFAULT NULL COMMENT Variable encryption method(fernet, simple, rsa, aes), salt varchar(128) DEFAULT NULL COMMENT Variable salt, scope varchar(32) DEFAULT global COMMENT Variable scope(global,flow,app,agent,datasource,flow_priv,agent_priv, etc), scope_key varchar(256) DEFAULT NULL COMMENT Variable scope key, default is empty, for scope is flow_priv, the scope_key is dag id of flow, enabled int DEFAULT 1 COMMENT Variable enabled, 0: disabled, 1: enabled, description text DEFAULT NULL COMMENT Variable description, user_name varchar(128) DEFAULT NULL COMMENT User name, sys_code varchar(128) DEFAULT NULL COMMENT System code, gmt_created datetime DEFAULT CURRENT_TIMESTAMP COMMENT Record creation time, gmt_modified datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT Record update time, PRIMARY KEY (id), KEY ix_your_table_name_key (key), KEY ix_your_table_name_name (name) ) ENGINEInnoDB AUTO_INCREMENT1 DEFAULT CHARSETutf8mb4 COLLATEutf8mb4_unicode_ci;该表是 v0.6.0 全局变量体系的核心对应 AWEL 工作流 / Agent 应用中的变量服务。ORM 映射与存储适配器位于 packages/dbgpt-serve/src/dbgpt_serve/flow/models/variables_adapter.py通过VariablesAdapter在StorageVariables核心接口模型与VariablesEntity数据库模型之间双向转换get_query_for_identifier按标识符过滤并强制enabled 1保证被禁用0的变量不会被读取。关键字段语义字段说明key/name/label变量标识、变量名与展示标签value变量值JSON 格式存储value_type值类型string、int、float、boolcategory类别common普通或secret机密encryption_method机密变量的加密方式fernet、simple、rsa、aesscope变量作用域global、flow、app、agent、datasource、flow_priv、agent_priv等scope_key作用域键如flow_priv时取对应 flow 的 dag idenabled是否启用0禁用 /1启用变量服务在 packages/dbgpt-serve/src/dbgpt_serve/flow/service/variables_service.py 中对外提供能力被 Flow 编排、Agent 资源绑定等多处引用。dbgpt_serve_dbgpts_my 与 dbgpt_serve_dbgpts_hub插件体系-- dbgpt.dbgpt_serve_dbgpts_my definition CREATE TABLE dbgpt_serve_dbgpts_my ( id int NOT NULL AUTO_INCREMENT COMMENT autoincrement id, name varchar(255) NOT NULL COMMENT plugin name, user_name varchar(255) DEFAULT NULL COMMENT user name, file_name varchar(255) NOT NULL COMMENT plugin package file name, type varchar(255) DEFAULT NULL COMMENT plugin type, version varchar(255) DEFAULT NULL COMMENT plugin version, use_count int DEFAULT NULL COMMENT plugin total use count, succ_count int DEFAULT NULL COMMENT plugin total success count, sys_code varchar(128) DEFAULT NULL COMMENT System code, gmt_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT plugin install time, gmt_modified TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT update time, PRIMARY KEY (id), UNIQUE KEY name (name, user_name), KEY ix_my_plugin_sys_code (sys_code) ) ENGINEInnoDB AUTO_INCREMENT1 DEFAULT CHARSETutf8mb4 COLLATEutf8mb4_unicode_ci; -- dbgpt.dbgpt_serve_dbgpts_hub definition CREATE TABLE dbgpt_serve_dbgpts_hub ( id int NOT NULL AUTO_INCREMENT COMMENT autoincrement id, name varchar(255) NOT NULL COMMENT plugin name, description varchar(255) NULL COMMENT plugin description, author varchar(255) DEFAULT NULL COMMENT plugin author, email varchar(255) DEFAULT NULL COMMENT plugin author email, type varchar(255) DEFAULT NULL COMMENT plugin type, version varchar(255) DEFAULT NULL COMMENT plugin version, storage_channel varchar(255) DEFAULT NULL COMMENT plugin storage channel, storage_url varchar(255) DEFAULT NULL COMMENT plugin download url, download_param varchar(255) DEFAULT NULL COMMENT plugin download param, gmt_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT plugin upload time, gmt_modified TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT update time, installed int DEFAULT NULL COMMENT plugin already installed count, PRIMARY KEY (id), UNIQUE KEY name (name) ) ENGINEInnoDB AUTO_INCREMENT1 DEFAULT CHARSETutf8mb4 COLLATEutf8mb4_unicode_ci;这两张表将 v0.5.10 中的my_plugin、plugin_hub升级为 dbgpts 插件体系的服务化存储dbgpt_serve_dbgpts_my记录用户已安装的插件包唯一键为(name, user_name)use_count/succ_count统计使用与成功次数dbgpt_serve_dbgpts_hub记录插件市场的插件信息storage_channel/storage_url描述下载来源installed统计安装数量插件名全局唯一。对应服务模块位于 packages/dbgpt-serve/src/dbgpt_serve/dbgpts/my/ 与 packages/dbgpt-serve/src/dbgpt_serve/dbgpts/hub/。升级注意事项与验证建议按库执行所有语句均在USE dbgpt;之后执行升级前请确认当前连接的 MySQL 实例中存在dbgpt库且为 v0.5.10 结构可对照 v0.5.10.sql 基线核对存量表。字段顺序敏感chat_history.app_code使用after message_ids指定插入位置其余字段默认追加到表尾重复执行会导致“Duplicate column name”报错因此升级脚本应只执行一次。字符集与引擎新表统一使用InnoDB引擎、utf8mb4字符集与utf8mb4_unicode_ci排序规则与存量表保持一致避免中文场景下的编码问题。索引必要性recommend_question的idx_rec_q_app_code、user_recent_apps的idx_last_accessed/idx_user_code等索引与 ORM 中的Index定义一一对应是列表查询性能的关键不建议删除。升级后验证重启 DB-GPT 服务后可在“应用Apps”页面确认推荐问题、最近使用、发布状态等功能正常也可通过SHOW COLUMNS FROM gpts_app;等命令核对新字段是否生效。SQLite 用户官方明确说明 SQLite 无需执行本升级脚本直接替换新版程序即可SQLite 表结构由 ORM 自动适配。结语v0.6.0 的数据库升级本质上是一次面向“Agent 应用平台化”的模型重构gpts_app的发布与协作字段让应用可运营recommend_question与user_recent_apps增强了应用入口体验dbgpt_serve_file与dbgpt_serve_variables为文件与变量提供了统一服务dbgpt_serve_dbgpts_*则重构了插件体系。对照本文档与仓库中 assets/schema/upgrade/v0_6_0/ 的脚本、gpts_app.py 等源码即可在动手迁移前完整掌握每个字段的设计意图从而更稳妥地完成从 v0.5.10 到 v0.6.0 的平滑升级。【免费下载链接】DB-GPTopen-source agentic AI data assistant for the next generation of AI Data products.项目地址: https://gitcode.com/GitHub_Trending/db/DB-GPT创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
分享:

看完干货,该让你的企业上线了

免费需求沟通 · 48 小时内出具建站方案 · 河南本地可上门