fix(log): F6 polish — log datasource create error log + schema patches for auth_type/token/headers + ES default index sync on datasource select

This commit is contained in:
attacker committed 2026-06-28 06:04:18 +08:00
1 parent 6bba6144f3
commit 5fb74a787a
3 files changed
+17 -6

No files matched your search

+3
View File
@@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"io"
"log"
"net/http"
"strings"
"time"
@@ -76,6 +77,8 @@ func (h *LogDSHandler) Create(c *gin.Context) {
IsDefault: req.IsDefault, Status: 1,
}
if err := h.db.Create(&ds).Error; err != nil {
// 记录详细错误,便于排查字段缺失/唯一约束等数据库问题 // Logan.Li
log.Printf("[LogDataSource] 创建数据源失败: %v", err)
if errors.Is(err, gorm.ErrDuplicatedKey) {
c.JSON(409, model.Response{Code: 409, Message: "数据源名称已存在"})
return
+12
View File
@@ -192,4 +192,16 @@ func applySchemaPatches(db *gorm.DB) {
patchUserColumn("ApiAccessKeyDescription", "api_access_key_description")
patchUserColumn("ApiAccessKeyDurationMonths", "api_access_key_duration_months")
patchUserColumn("ApiAccessKeyLastUsedAt", "api_access_key_last_used_at")
// 补全日志数据源表可能缺失的列(旧表仅有基础字段)// Logan.Li
patchLogDSColumn := func(field string, col string) {
if !m.HasColumn(&model.LogDataSource{}, col) {
if err := m.AddColumn(&model.LogDataSource{}, field); err != nil {
log.Printf("[DB] 补列 monitor_log_datasources.%s 失败: %v", col, err)
}
}
}
patchLogDSColumn("AuthType", "auth_type")
patchLogDSColumn("Token", "token")
patchLogDSColumn("Headers", "headers")
}