From 58d9891205c2da0f5a2dcbb55b7c3186ceeff46f Mon Sep 17 00:00:00 2001 From: qhd <1766646056@qq.com> Date: Sat, 29 Aug 2026 14:39:18 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=AD=98=E9=87=8F=E6=8B=B7=E8=B4=9D?= =?UTF-8?q?=E8=BD=AC=E5=BC=95=E7=94=A8=E8=BF=81=E7=A7=BB=20SQL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 按同名系统模型把存量拷贝行转引用行(配置列清空、幂等、ref_system_model_id 守卫) Co-Authored-By: Claude --- update.sql | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/update.sql b/update.sql index 898c45b..f808458 100644 --- a/update.sql +++ b/update.sql @@ -328,4 +328,29 @@ ALTER TABLE model_gateway_model_manage COMMENT ON COLUMN model_gateway_model_manage.ref_system_model_id IS '引用的系统模型ID(NULL=非引用行;system_model=false 且该列非空=引用行)'; CREATE INDEX IF NOT EXISTS idx_model_manage_ref_system_model_id - ON model_gateway_model_manage(ref_system_model_id); \ No newline at end of file + ON model_gateway_model_manage(ref_system_model_id); + +-- ========================= +-- 存量迁移:拷贝行 → 引用行(按同名系统模型匹配,一次性,幂等) +-- 前提:存量拷贝均原封不动、无自定义(用户已确认)。若存在用户独立创建的同名自有模型会被误转,执行前复核一次: +-- SELECT r.id, r.creator, r.model_name, r.ref_system_model_id, s.id AS sys_id +-- FROM model_gateway_model_manage r +-- JOIN model_gateway_model_manage s ON s.model_name = r.model_name AND s.system_model = true +-- WHERE r.system_model = false AND r.ref_system_model_id IS NOT NULL; +-- 列名以 entity orm 为准(update.sql 顶部旧 DDL 已过时)。 +-- ========================= +UPDATE model_gateway_model_manage r SET + ref_system_model_id = s.id, + base_url = NULL, http_method = NULL, + request_head_mapping = NULL, request_body_mapping = NULL, + request_business_field_mapping = NULL, + response_mapping = NULL, response_body_mapping = NULL, + response_business_field_mapping = NULL, + max_concurrency = 0, token_mapping = NULL, async_task_mapping = NULL, + token_predict_price = 0, token_predict_price_unit = NULL, + max_tokens = 0, min_duration = 0, max_duration = 0, + last_frame = NULL, error_message_mapping = NULL +FROM model_gateway_model_manage s +WHERE r.system_model = false AND s.system_model = true + AND r.model_name = s.model_name + AND r.ref_system_model_id IS NULL; \ No newline at end of file