From 0f555b7ec74ad493d2f70a4f4040db333943dc1c Mon Sep 17 00:00:00 2001 From: kolaente Date: Thu, 21 Jul 2022 14:54:52 +0200 Subject: [PATCH] fix: reset id sequence when importing a dump from postgres --- pkg/db/dump.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pkg/db/dump.go b/pkg/db/dump.go index fde6d473763..39ac3a2c61d 100644 --- a/pkg/db/dump.go +++ b/pkg/db/dump.go @@ -17,10 +17,8 @@ package db import ( - "encoding/json" - "strconv" - "code.vikunja.io/api/pkg/log" + "encoding/json" "xorm.io/xorm/schemas" ) @@ -62,7 +60,7 @@ 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);") + _, err = x.Query("SELECT setval('" + idSequence + "', COALESCE(MAX(id), 1) )") if err != nil { log.Warningf("Could not reset id sequence for %s: %s", idSequence, err) err = nil