mirror of https://github.com/veypi/OneAuth.git
refactor(cfg): Restructure database configuration and initialization flow
- Replace separate DB/DSN fields with unified config.Database struct
- Remove cfg/db.go and move DB client to config.Database.Client()
- Update auth to use event-driven initialization via vb.init.auth event
- Refactor models initialization to use event system (vb.init.settings/oauth/admin)
- Update CLI to use event.Start() instead of manual InitDB() call
- Fix auth_test.go to use new DB config structure
- Update agents.md documentation with new CLI flags format
master
parent
23c7f6cb7a
commit
4a57017067
@ -1,41 +0,0 @@
|
|||||||
//
|
|
||||||
// db.go
|
|
||||||
// Copyright (C) 2024 veypi <i@veypi.com>
|
|
||||||
// 2025-03-04 16:08:06
|
|
||||||
// Distributed under terms of the MIT license.
|
|
||||||
//
|
|
||||||
|
|
||||||
package cfg
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/glebarez/sqlite"
|
|
||||||
"gorm.io/driver/mysql"
|
|
||||||
"gorm.io/driver/postgres"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
"gorm.io/gorm/logger"
|
|
||||||
)
|
|
||||||
|
|
||||||
var db *gorm.DB
|
|
||||||
|
|
||||||
func DB() *gorm.DB {
|
|
||||||
if db == nil {
|
|
||||||
var err error
|
|
||||||
var conn gorm.Dialector
|
|
||||||
switch Config.DB {
|
|
||||||
case "mysql":
|
|
||||||
conn = mysql.Open(Config.DSN)
|
|
||||||
case "postgres":
|
|
||||||
conn = postgres.Open(Config.DSN)
|
|
||||||
default:
|
|
||||||
conn = sqlite.Open(Config.DSN)
|
|
||||||
}
|
|
||||||
db, err = gorm.Open(conn,
|
|
||||||
&gorm.Config{
|
|
||||||
Logger: logger.Default.LogMode(logger.Silent),
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return db
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue