diff --git a/internal/application/application.go b/internal/application/application.go index 6acb748..7719c37 100644 --- a/internal/application/application.go +++ b/internal/application/application.go @@ -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) diff --git a/internal/db/Schema.go b/internal/db/Schema.go index 22b349d..0d7f6bb 100644 --- a/internal/db/Schema.go +++ b/internal/db/Schema.go @@ -19,11 +19,6 @@ type AppConfig struct { 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 { gorm.Model Timestamp int64 diff --git a/internal/db/queries.go b/internal/db/queries.go index 456578e..de2ed52 100644 --- a/internal/db/queries.go +++ b/internal/db/queries.go @@ -10,5 +10,5 @@ func GetConfig(db *gorm.DB) (*AppConfig, error) { return nil, err } - return &cfg, err + return &cfg, nil }