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 return
} }
// Populate the initial Config cache OR create defaults
firstRun := false firstRun := false
startupConfig, err := db.GetConfig(DB)
// Populate the initial Config cache OR create defaults
cfg, err := db.GetConfig(DB)
if err != nil { if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) { if errors.Is(err, gorm.ErrRecordNotFound) {
logger.Info("No config found in database, generating defaults")
firstRun = true firstRun = true
startupConfig = &db.AppConfig{ cfg = &db.AppConfig{
Model: gorm.Model{ID: 1},
DataDir: dataDir, DataDir: dataDir,
AssetsDir: dataDir, AssetsDir: dataDir,
SystemLevel: "BASIC", SystemLevel: "BASIC",
@@ -125,14 +126,11 @@ func Run() {
SavedVolume: 1.0, SavedVolume: 1.0,
} }
// Now save it to the database to create the config for all subsequent queries if err := DB.Create(cfg).Error; err != nil {
if err := DB.Create(&startupConfig).Error; err != nil { logger.Error("failed to create config: %v", err)
logger.Error("failed to insert default config into database: %v", err)
return return
} }
} }
logger.Error("failed to read configuration from database")
return
} }
logger.AddDatabase(DB) logger.AddDatabase(DB)
-5
View File
@@ -19,11 +19,6 @@ type AppConfig struct {
FirstRun bool // Is this the first time the application has been run? FirstRun bool // Is this the first time the application has been run?
} }
// Explicit table name to avoid pluralization issues
func (AppConfig) TableName() string {
return "app_configs" // Use your ACTUAL table name (check with: sqlite3 database.sqlite ".tables")
}
type Log struct { type Log struct {
gorm.Model gorm.Model
Timestamp int64 Timestamp int64
+1 -1
View File
@@ -10,5 +10,5 @@ func GetConfig(db *gorm.DB) (*AppConfig, error) {
return nil, err return nil, err
} }
return &cfg, err return &cfg, nil
} }