diff --git a/cmd/server/main.go b/cmd/server/main.go index 8649014..78acf4c 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -10,6 +10,7 @@ import ( "os" "os/signal" "path/filepath" + "strings" "syscall" "time" @@ -82,7 +83,8 @@ func main() { continue } for _, cal := range cals { - if err := st.EnsureCollection(user.Username, "cal-"+cal.Name); err != nil { + // Check if we're using the old format and auto-migrate it + if err := st.EnsureCollection(user.Username, "calendars/"+cal.Name); err != nil { logger.Warn("creating calendar collection", "user", user.Username, "cal", cal.Name, "error", err) } } @@ -92,12 +94,16 @@ func main() { continue } for _, book := range books { - if err := st.EnsureCollection(user.Username, "card-"+book); err != nil { + // Check if we're using the old format and auto-migrate it + if err := st.EnsureCollection(user.Username, "addressbooks/"+book); err != nil { logger.Warn("creating address book collection", "user", user.Username, "book", book, "error", err) } } } + // Auto-migrate old data structures if they exist + migrateOldPaths(st, cfg.Storage.DataDir, logger) + // ---- Middleware ---- authMw := auth.NewMiddleware(cfg, dbase, logger) @@ -284,3 +290,110 @@ const welcomePage = `