Resolve empty config issue

This commit is contained in:
NeilClack
2026-06-26 23:35:29 -05:00
parent 6274687fe8
commit 3ef8f3db92
3 changed files with 8 additions and 15 deletions
+7 -9
View File
@@ -106,14 +106,15 @@ func Run() {
return
}
// Populate the initial Config cache OR create defaults
firstRun := false
startupConfig, err := db.GetConfig(DB)
// Populate the initial Config cache OR create defaults
cfg, err := db.GetConfig(DB)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
logger.Info("No config found in database, generating defaults")
firstRun = true
startupConfig = &db.AppConfig{
cfg = &db.AppConfig{
Model: gorm.Model{ID: 1},
DataDir: dataDir,
AssetsDir: dataDir,
SystemLevel: "BASIC",
@@ -125,14 +126,11 @@ func Run() {
SavedVolume: 1.0,
}
// Now save it to the database to create the config for all subsequent queries
if err := DB.Create(&startupConfig).Error; err != nil {
logger.Error("failed to insert default config into database: %v", err)
if err := DB.Create(cfg).Error; err != nil {
logger.Error("failed to create config: %v", err)
return
}
}
logger.Error("failed to read configuration from database")
return
}
logger.AddDatabase(DB)