diff --git a/config.go b/config.go index 23a138a..7fb388c 100644 --- a/config.go +++ b/config.go @@ -37,8 +37,6 @@ func (app *appContext) loadConfig() error { return err } - app.MustSetValue("", "migrated_to_db", "false") - app.MustSetValue("jellyfin", "public_server", app.config.Section("jellyfin").Key("server").String()) app.MustSetValue("ui", "redirect_url", app.config.Section("jellyfin").Key("public_server").String()) diff --git a/migrations.go b/migrations.go index 99f0d07..e2e32ab 100644 --- a/migrations.go +++ b/migrations.go @@ -196,10 +196,17 @@ func linkExistingOmbiDiscordTelegram(app *appContext) error { return nil } +// MigrationStatus is just used to store whether data from JSON files has been migrated to the DB. +type MigrationStatus struct { + Done bool +} + func migrateToBadger(app *appContext) { - if app.config.Section("").Key("migrated_to_db").MustBool(false) { + // Check the DB to see if we've already migrated + migrated := MigrationStatus{} + app.storage.db.Get("migrated_to_db", &migrated) + if migrated.Done { return - // FIXME: Mark as done at some point } app.info.Println("Migrating to Badger(hold)") app.storage.loadAnnouncements() @@ -281,9 +288,10 @@ func migrateToBadger(app *appContext) { app.storage.SetCustomContentKey("UserPage", app.storage.deprecatedUserPageContent.Page) } - tempConfig, _ := ini.Load(app.configPath) - tempConfig.Section("").Key("migrated_to_db").SetValue("true") - tempConfig.SaveTo(app.configPath) + err := app.storage.db.Upsert("migrated_to_db", MigrationStatus{true}) + if err != nil { + app.err.Fatalf("Failed to migrate to DB: %v\n", err) + } app.info.Println("All data migrated to database. JSON files in the config folder can be deleted if you are sure all data is correct in the app. Create an issue if you have problems.") }