From 6e15d46a93655bdb89e92d94069536b9496ea7b1 Mon Sep 17 00:00:00 2001 From: kolaente Date: Wed, 13 Jul 2022 23:44:21 +0200 Subject: [PATCH] fix(restore): use the correct initial migration Related to https://kolaente.dev/vikunja/api/issues/1199 --- pkg/modules/dump/restore.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/modules/dump/restore.go b/pkg/modules/dump/restore.go index c7bfa9b9..723cae28 100644 --- a/pkg/modules/dump/restore.go +++ b/pkg/modules/dump/restore.go @@ -20,6 +20,7 @@ import ( "archive/zip" "bufio" "bytes" + "encoding/base64" "encoding/json" "fmt" "io" @@ -122,14 +123,17 @@ func Restore(filename string) error { return fmt.Errorf("could not read migrations: %w", err) } sort.Slice(ms, func(i, j int) bool { - return ms[i].ID > ms[j].ID + return ms[i].ID < ms[j].ID }) - lastMigration := ms[len(ms)-1] + lastMigration := ms[len(ms)-2] + log.Debugf("Last migration: %s", lastMigration.ID) if err := migration.MigrateTo(lastMigration.ID, nil); err != nil { return fmt.Errorf("could not create db structure: %w", err) } + delete(dbfiles, "migration") + // Restore all db data for table, d := range dbfiles { content, err := unmarshalFileToJSON(d)