fix db path

This commit is contained in:
Sakurasan
2025-04-17 02:37:41 +08:00
parent 9ed162ff0c
commit c8e565c6a4
2 changed files with 38 additions and 1 deletions

View File

@@ -5,6 +5,7 @@ import (
"log"
"opencatd-open/internal/model"
"opencatd-open/pkg/config"
"os"
"strings"
// "gocloud.dev/mysql"
@@ -77,7 +78,13 @@ func InitDB(cfg *config.Config) (*gorm.DB, error) {
// initSQLite 初始化 SQLite 数据库
func initSQLite() (*gorm.DB, error) {
db, err := gorm.Open(sqlite.Open("openteam.db"), &gorm.Config{})
if _, err := os.Stat("db"); os.IsNotExist(err) {
errDir := os.MkdirAll("db", 0755)
if errDir != nil {
log.Fatalln("Error creating directory:", err)
}
}
db, err := gorm.Open(sqlite.Open("./db/openteam.db"), &gorm.Config{})
if err != nil {
return nil, fmt.Errorf("failed to connect to SQLite: %v", err)
}