This commit is contained in:
2026-08-05 13:43:48 +08:00
parent b11ed5b433
commit 20c1805efb
2 changed files with 10 additions and 10 deletions
+2 -3
View File
@@ -42,10 +42,9 @@ func init() {
{"chunk_overlap", "chunk_overlap INTEGER NOT NULL DEFAULT 150"},
{"chunk_strategy", "chunk_strategy TEXT NOT NULL DEFAULT 'title'"},
} {
var n int
err := g.DB(consts.DbGroupDefault).Ctx(ctx).GetScan(ctx, &n,
cnt, err := g.DB(consts.DbGroupDefault).Ctx(ctx).GetValue(ctx,
"SELECT COUNT(*) FROM pragma_table_info('"+consts.TableNameDataset+"') WHERE name=?", col.name)
if err != nil || n > 0 {
if err != nil || cnt.Int64() > 0 {
continue
}
if _, err := g.DB(consts.DbGroupDefault).Exec(ctx,
+8 -7
View File
@@ -38,18 +38,19 @@ func init() {
g.Log().Warningf(ctx, "create model_config table failed: %v", err)
}
// 迁移:旧库补 is_default 列,并把 system_config 中的旧默认对话模型键迁移为 is_default
var n int
if err := g.DB(consts.DbGroupSystem).Ctx(ctx).GetScan(ctx, &n,
"SELECT COUNT(*) FROM pragma_table_info('"+consts.TableNameModelConfig+"') WHERE name=?", "is_default"); err == nil && n == 0 {
// 注意:GetScan 只支持 struct/slice 指针,标量查询用 Value
cnt, err := g.DB(consts.DbGroupSystem).Ctx(ctx).GetValue(ctx,
"SELECT COUNT(*) FROM pragma_table_info('"+consts.TableNameModelConfig+"') WHERE name=?", "is_default")
if err == nil && cnt.Int64() == 0 {
if _, err := g.DB(consts.DbGroupSystem).Exec(ctx, "ALTER TABLE "+consts.TableNameModelConfig+" ADD COLUMN is_default INTEGER NOT NULL DEFAULT 0"); err != nil {
g.Log().Warningf(ctx, "alter model_config add is_default failed: %v", err)
} else {
var old int64
if err := g.DB(consts.DbGroupSystem).Ctx(ctx).GetScan(ctx, &old,
"SELECT cfg_value FROM system_config WHERE cfg_key='default_chat_model'"); err == nil && old > 0 {
old, err := g.DB(consts.DbGroupSystem).Ctx(ctx).GetValue(ctx,
"SELECT cfg_value FROM system_config WHERE cfg_key='default_chat_model'")
if err == nil && old.Int64() > 0 {
if _, err := g.DB(consts.DbGroupSystem).Exec(ctx,
"UPDATE "+consts.TableNameModelConfig+" SET is_default=CASE WHEN id=? THEN 1 ELSE 0 END WHERE model_type=?",
old, consts.ModelTypeChat); err != nil {
old.Int64(), consts.ModelTypeChat); err != nil {
g.Log().Warningf(ctx, "migrate default_chat_model to is_default failed: %v", err)
}
}