mirror of
https://github.com/hrfee/jfa-go.git
synced 2024-12-22 09:00:10 +00:00
db: use db key to store migration status
the planned config key "migrated_to_db" is not used, instead it is stored in the database since that's a bit cleaner.
This commit is contained in:
parent
e9f9d9dc98
commit
28c3d9d2e4
@ -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())
|
||||
|
@ -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.")
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user