fix(build): 独立二进制输出到根目录并修复 local 模式 SQLite 路径
- SQLite/redka 数据目录相对可执行文件解析,自动创建 data/ 父目录 - ./run.sh build 产物改为 ./aiops(与 run.sh 同级),数据/日志在 ./data ./logs - 解决从项目根执行时 data/ 不存在导致的 SQLite CANTOPEN 报错
This commit is contained in:
1 parent
fd7b04b9d6
commit
e7a479ccf5
5 files changed
+88
-31
No files matched your search
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"ezops/config"
|
||||
"ezops/model"
|
||||
"ezops/pkg/appdir"
|
||||
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/driver/postgres"
|
||||
@@ -29,7 +30,10 @@ func New(cfg config.DatabaseConfig) (*gorm.DB, error) {
|
||||
cfg.Host, cfg.Port, cfg.User, cfg.Password, cfg.DBName)
|
||||
dialector = postgres.Open(dsn)
|
||||
case "sqlite":
|
||||
dsn := cfg.DBName
|
||||
dsn := appdir.Resolve(cfg.DBName)
|
||||
if err := appdir.EnsureParentDir(dsn); err != nil {
|
||||
return nil, fmt.Errorf("创建数据库目录失败: %w", err)
|
||||
}
|
||||
if !strings.Contains(dsn, "?") {
|
||||
// WAL 提升并发读,busy_timeout 降低锁冲突 // Logan.Li
|
||||
dsn += "?_pragma=journal_mode(WAL)&_pragma=busy_timeout(5000)"
|
||||
|
||||
Reference in new issue
Block a user