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