chore: 存量拷贝转引用迁移 SQL

按同名系统模型把存量拷贝行转引用行(配置列清空、幂等、ref_system_model_id 守卫)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-08-29 14:39:18 +08:00
co-authored by Claude
parent 6cff7a934b
commit 58d9891205
+26 -1
View File
@@ -328,4 +328,29 @@ ALTER TABLE model_gateway_model_manage
COMMENT ON COLUMN model_gateway_model_manage.ref_system_model_id
IS '引用的系统模型IDNULL=非引用行;system_model=false 且该列非空=引用行)';
CREATE INDEX IF NOT EXISTS idx_model_manage_ref_system_model_id
ON model_gateway_model_manage(ref_system_model_id);
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;