From 19715f25f6266f0d360efa745aec96e8cc6aa4a5 Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Tue, 1 Jun 2021 14:18:49 +0100 Subject: [PATCH] Move all migrations to separate file Also fixed some inconsistent uses of snake case. --- config.go | 50 ----------- html/admin.html | 8 +- daemon.go => invdaemon.go | 2 +- main.go | 107 +--------------------- migrations.go | 180 ++++++++++++++++++++++++++++++++++++++ tray.go | 1 - views.go | 34 +++---- 7 files changed, 205 insertions(+), 177 deletions(-) rename daemon.go => invdaemon.go (96%) create mode 100644 migrations.go diff --git a/config.go b/config.go index e0e9ba3..6c25356 100644 --- a/config.go +++ b/config.go @@ -151,53 +151,3 @@ func (app *appContext) loadConfig() error { return nil } - -func (app *appContext) migrateEmailConfig() { - tempConfig, _ := ini.Load(app.configPath) - fmt.Println(warning("Part of your email configuration will be migrated to the new \"messages\" section.\nA backup will be made.")) - err := tempConfig.SaveTo(app.configPath + "_" + commit + ".bak") - if err != nil { - app.err.Fatalf("Failed to backup config: %v", err) - return - } - for _, setting := range []string{"use_24h", "date_format", "message"} { - if val := app.config.Section("email").Key(setting).Value(); val != "" { - tempConfig.Section("email").Key(setting).SetValue("") - tempConfig.Section("messages").Key(setting).SetValue(val) - } - } - if app.config.Section("messages").Key("enabled").MustBool(false) || app.config.Section("telegram").Key("enabled").MustBool(false) { - tempConfig.Section("messages").Key("enabled").SetValue("true") - } - err = tempConfig.SaveTo(app.configPath) - if err != nil { - app.err.Fatalf("Failed to save config: %v", err) - return - } - app.loadConfig() -} - -func (app *appContext) migrateEmailStorage() error { - var emails map[string]interface{} - err := loadJSON(app.storage.emails_path, &emails) - if err != nil { - return err - } - newEmails := map[string]EmailAddress{} - for jfID, addr := range emails { - newEmails[jfID] = EmailAddress{ - Addr: addr.(string), - Contact: true, - } - } - err = storeJSON(app.storage.emails_path+".bak", emails) - if err != nil { - return err - } - err = storeJSON(app.storage.emails_path, newEmails) - if err != nil { - return err - } - app.info.Println("Migrated to new email format. A backup has also been made.") - return nil -} diff --git a/html/admin.html b/html/admin.html index a486455..4bc1472 100644 --- a/html/admin.html +++ b/html/admin.html @@ -5,10 +5,10 @@