fix(restore): make sure to reset sequences after importing a dump when using postgres
Related to https://kolaente.dev/vikunja/api/issues/1199
This commit is contained in:
parent
596d2bf676
commit
54348c5891
1 changed files with 12 additions and 0 deletions
|
@ -18,6 +18,9 @@ package db
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
|
||||
"code.vikunja.io/api/pkg/log"
|
||||
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
@ -57,6 +60,15 @@ func Restore(table string, contents []map[string]interface{}) (err error) {
|
|||
}
|
||||
}
|
||||
|
||||
if Type() == schemas.POSTGRES {
|
||||
idSequence := table + "_id_seq"
|
||||
_, err = x.Query("SELECT setval('" + idSequence + "', " + strconv.Itoa(len(contents)) + ", true);")
|
||||
if err != nil {
|
||||
log.Warningf("Could not reset id sequence for %s: %s", idSequence, err)
|
||||
err = nil
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue