fix(restore): use the correct initial migration

Related to vikunja/api#1199
This commit is contained in:
kolaente 2022-07-13 23:44:21 +02:00
parent 54348c5891
commit 6e15d46a93
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 6 additions and 2 deletions

View File

@ -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)