mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-30 02:43:05 +00:00
Fix debug mode enabled by default in db
This commit is contained in:
parent
a16a763283
commit
29b80e3ca1
1 changed files with 12 additions and 3 deletions
15
db.go
15
db.go
|
@ -6,6 +6,7 @@ import (
|
||||||
"gorm.io/driver/postgres"
|
"gorm.io/driver/postgres"
|
||||||
"gorm.io/driver/sqlite"
|
"gorm.io/driver/sqlite"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
"gorm.io/gorm/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const dbVersion = "1"
|
const dbVersion = "1"
|
||||||
|
@ -50,23 +51,31 @@ func (h *Headscale) initDB() error {
|
||||||
func (h *Headscale) openDB() (*gorm.DB, error) {
|
func (h *Headscale) openDB() (*gorm.DB, error) {
|
||||||
var db *gorm.DB
|
var db *gorm.DB
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
var log logger.Interface
|
||||||
|
if h.dbDebug {
|
||||||
|
log = logger.Default
|
||||||
|
} else {
|
||||||
|
log = logger.Default.LogMode(logger.Silent)
|
||||||
|
}
|
||||||
|
|
||||||
switch h.dbType {
|
switch h.dbType {
|
||||||
case "sqlite3":
|
case "sqlite3":
|
||||||
db, err = gorm.Open(sqlite.Open(h.dbString), &gorm.Config{
|
db, err = gorm.Open(sqlite.Open(h.dbString), &gorm.Config{
|
||||||
DisableForeignKeyConstraintWhenMigrating: true,
|
DisableForeignKeyConstraintWhenMigrating: true,
|
||||||
|
Logger: log,
|
||||||
})
|
})
|
||||||
case "postgres":
|
case "postgres":
|
||||||
db, err = gorm.Open(postgres.Open(h.dbString), &gorm.Config{
|
db, err = gorm.Open(postgres.Open(h.dbString), &gorm.Config{
|
||||||
DisableForeignKeyConstraintWhenMigrating: true,
|
DisableForeignKeyConstraintWhenMigrating: true,
|
||||||
|
Logger: log,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if h.dbDebug {
|
|
||||||
db.Debug()
|
|
||||||
}
|
|
||||||
return db, nil
|
return db, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue