From 17f823064f1944c75bc72b68eb0039689ec251f4 Mon Sep 17 00:00:00 2001 From: finn Date: Tue, 1 Mar 2022 16:00:37 -0800 Subject: [PATCH] reset the value generator for SERIAL columns after import --- cmd/signaldctl/cmd/db/migrate.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cmd/signaldctl/cmd/db/migrate.go b/cmd/signaldctl/cmd/db/migrate.go index 7c57dd8..bad9eb0 100644 --- a/cmd/signaldctl/cmd/db/migrate.go +++ b/cmd/signaldctl/cmd/db/migrate.go @@ -230,6 +230,12 @@ func moveRecipients(source *sql.DB, dest *sql.DB) error { return err } } + + // start new rowids one above the current max value + _, err = dest.Exec("SELECT setval(pg_get_serial_sequence('signald_recipients', 'rowid', (SELECT MAX(rowid) FROM signald_recipients)+1);") + if err != nil { + return err + } return nil } @@ -494,6 +500,12 @@ func moveGroups(source *sql.DB, dest *sql.DB) error { return err } } + + // start new rowids one above the current max value + _, err = dest.Exec("SELECT setval(pg_get_serial_sequence('signald_groups', 'rowid', (SELECT MAX(rowid) FROM signald_groups)+1);") + if err != nil { + return err + } return nil }