summary refs log tree commit diff
path: root/scripts
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2020-07-16 11:46:44 +0100
committerRichard van der Hoff <richard@matrix.org>2020-07-16 13:00:25 +0100
commitc445bc0cadad6c9364b1495e6374d84a45e553c4 (patch)
tree22d875dd5541aed43833eba69e35c417f99e2c1c /scripts
parentUse SequenceGenerator for state group ID allocation (diff)
downloadsynapse-c445bc0cadad6c9364b1495e6374d84a45e553c4.tar.xz
Use a postgres sequence to generate guest user IDs
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/synapse_port_db12
1 files changed, 11 insertions, 1 deletions
diff --git a/scripts/synapse_port_db b/scripts/synapse_port_db
index 2eb795192f..22a6abd7d2 100755
--- a/scripts/synapse_port_db
+++ b/scripts/synapse_port_db
@@ -48,6 +48,7 @@ from synapse.storage.data_stores.main.media_repository import (
 )
 from synapse.storage.data_stores.main.registration import (
     RegistrationBackgroundUpdateStore,
+    find_max_generated_user_id_localpart,
 )
 from synapse.storage.data_stores.main.room import RoomBackgroundUpdateStore
 from synapse.storage.data_stores.main.roommember import RoomMemberBackgroundUpdateStore
@@ -622,8 +623,10 @@ class Porter(object):
                 )
             )
 
-            # Step 5. Do final post-processing
+            # Step 5. Set up sequences
+            self.progress.set_state("Setting up sequence generators")
             await self._setup_state_group_id_seq()
+            await self._setup_user_id_seq()
 
             self.progress.done()
         except Exception as e:
@@ -793,6 +796,13 @@ class Porter(object):
 
         return self.postgres_store.db.runInteraction("setup_state_group_id_seq", r)
 
+    def _setup_user_id_seq(self):
+        def r(txn):
+            next_id = find_max_generated_user_id_localpart(txn) + 1
+            txn.execute("ALTER SEQUENCE user_id_seq RESTART WITH %s", (next_id,))
+
+        return self.postgres_store.db.runInteraction("setup_user_id_seq", r)
+
 
 ##############################################
 # The following is simply UI stuff