From 9e88bfe6b44bbb347bf220698138205abbc89af3 Mon Sep 17 00:00:00 2001 From: MI3Guy <254386+MI3Guy@users.noreply.github.com> Date: Mon, 9 Oct 2023 10:35:52 -0400 Subject: [PATCH] docs: fix primary key in PG migration When importing data, Postgres doesn't update the auto increment counter for the groups. Creating a group after an import would fail due to duplicate IDs. This manually sets the ID to the max of the IDs + 1. --- docs/database_migration.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/database_migration.md b/docs/database_migration.md index 7973513..2aa3930 100644 --- a/docs/database_migration.md +++ b/docs/database_migration.md @@ -53,6 +53,7 @@ format to PostgreSQL format, and wrap it all in a transaction: sed -i -r -e "s/X'([[:xdigit:]]+'[^'])/'\\\x\\1/g" \ -e ":a; s/(INSERT INTO user_attribute_schema\(.*\) VALUES\(.*),1([^']*\);)$/\1,true\2/; s/(INSERT INTO user_attribute_schema\(.*\) VALUES\(.*),0([^']*\);)$/\1,false\2/; ta" \ -e '1s/^/BEGIN;\n/' \ +-e '$aSELECT setval(pg_get_serial_sequence('\''groups'\'', '\''group_id'\''), COALESCE((SELECT MAX(group_id) FROM groups), 1));' \ -e '$aCOMMIT;' /path/to/dump.sql ```