mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-06-18 10:06:26 +00:00
Convert db backend to use Gorm, with basis for support
for Mysql and Postgres in addition to existing Sqlite
This commit is contained in:
@ -11,6 +11,8 @@ import (
|
||||
"npm/internal/entity/certificate"
|
||||
"npm/internal/entity/host"
|
||||
"npm/internal/entity/setting"
|
||||
"npm/internal/entity/user"
|
||||
"npm/internal/errors"
|
||||
"npm/internal/jobqueue"
|
||||
"npm/internal/logger"
|
||||
)
|
||||
@ -25,7 +27,7 @@ func main() {
|
||||
|
||||
database.Migrate(func() {
|
||||
setting.ApplySettings()
|
||||
database.CheckSetup()
|
||||
checkSetup()
|
||||
|
||||
// Internal Job Queue
|
||||
jobqueue.Start()
|
||||
@ -41,7 +43,8 @@ func main() {
|
||||
if irq == syscall.SIGINT || irq == syscall.SIGTERM {
|
||||
logger.Info("Got ", irq, " shutting server down ...")
|
||||
// Close db
|
||||
err := database.GetInstance().Close()
|
||||
sqlDB, _ := database.GetDB().DB()
|
||||
err := sqlDB.Close()
|
||||
if err != nil {
|
||||
logger.Error("DatabaseCloseError", err)
|
||||
}
|
||||
@ -52,3 +55,28 @@ func main() {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// checkSetup Quick check by counting the number of users in the database
|
||||
func checkSetup() {
|
||||
db := database.GetDB()
|
||||
var count int64
|
||||
|
||||
if db != nil {
|
||||
db.Model(&user.Model{}).
|
||||
Where("is_disabled = ?", false).
|
||||
Where("is_system = ?", false).
|
||||
Count(&count)
|
||||
|
||||
if count == 0 {
|
||||
logger.Warn("No users found, starting in Setup Mode")
|
||||
} else {
|
||||
config.IsSetup = true
|
||||
logger.Info("Application is setup")
|
||||
}
|
||||
if config.ErrorReporting {
|
||||
logger.Warn("Error reporting is enabled - Application Errors WILL be sent to Sentry, you can disable this in the Settings interface")
|
||||
}
|
||||
} else {
|
||||
logger.Error("DatabaseError", errors.ErrDatabaseUnavailable)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user