修复DB模块代码

This commit is contained in:
2026-02-18 18:07:22 +08:00
parent bf1df59bc8
commit 18a42d4a23
2 changed files with 10 additions and 4 deletions

View File

@@ -108,11 +108,9 @@ func (d *DB) InitSchema(force bool) error {
return err return err
} }
log.Info("已清空现有数据库触发器") log.Info("已清空现有--数据库触发器")
return createTables(d.engine) return createTables(d.engine)
} }
log.Info("数据库创建成功")
return nil return nil
} }
@@ -140,6 +138,14 @@ func createTables(db *sql.DB) error {
} }
} }
log.Info("数据库表创建成功") log.Info("数据库表创建成功")
/*
使用sqlite3命令 测试数据库是否存在表
✅ 查询所有表
sqlite3 /var/lib/sunhpc/sunhpc.db
.tables # 查看所有表
select * from sqlite_master where type='table'; # 查看表定义
PRAGMA integrity_check; # 检查数据库完整性
*/
return nil return nil
} }
@@ -209,7 +215,7 @@ func (d *DB) Connect(allowCreate bool) error {
return fmt.Errorf("创建数据库目录失败: %w", err) return fmt.Errorf("创建数据库目录失败: %w", err)
} }
// 连接参数 // 连接参数, 开启外键约束(PRAGMA foreign_keys = ON)、WAL 模式、5秒超时
dsn := fmt.Sprintf("%s?_foreign_keys=on&_journal_mode=WAL&_timeout=5000", dsn := fmt.Sprintf("%s?_foreign_keys=on&_journal_mode=WAL&_timeout=5000",
fullPath) fullPath)

BIN
sunhpc

Binary file not shown.