优化 local 模式兼容性与部署可靠性

- SQL 方言层:agent updated_at、dashboard 小时分桶、清理任务跨 SQLite/MySQL
- Cache Capabilities:redka 跳过 ZSet/PubSub,Agent 聚合改 DB 直读
- local 模式 redka 初始化失败 Fatal;/version 返回 features
- SQLite WAL + 连接池限制;K8s data 改 PVC 持久化
- run.sh:旧参数迁移、升级后 /version 校验
This commit is contained in:
Logan.Li committed 2026-06-26 13:28:31 +08:00
1 parent 1f4f63cf6e
commit b7166acda4
13 files changed
+374 -152

No files matched your search

+13 -1
View File
@@ -2,6 +2,7 @@ package database
import (
"fmt"
"strings"
"time"
"ezops/config"
@@ -28,7 +29,18 @@ func New(cfg config.DatabaseConfig) (*gorm.DB, error) {
cfg.Host, cfg.Port, cfg.User, cfg.Password, cfg.DBName)
dialector = postgres.Open(dsn)
case "sqlite":
dialector = sqlite.Open(cfg.DBName)
dsn := cfg.DBName
if !strings.Contains(dsn, "?") {
// WAL 提升并发读,busy_timeout 降低锁冲突 // Logan.Li
dsn += "?_pragma=journal_mode(WAL)&_pragma=busy_timeout(5000)"
}
dialector = sqlite.Open(dsn)
if cfg.MaxConn > 4 {
cfg.MaxConn = 4
}
if cfg.MaxIdle > 2 {
cfg.MaxIdle = 2
}
default:
return nil, fmt.Errorf("unsupported database driver: %s", cfg.Driver)
}