diff --git a/synapse/_scripts/synapse_port_db.py b/synapse/_scripts/synapse_port_db.py index 7c4aa0afa269..6446f0f6cf9c 100755 --- a/synapse/_scripts/synapse_port_db.py +++ b/synapse/_scripts/synapse_port_db.py @@ -769,6 +769,10 @@ def alter_table(txn: LoggingTransaction) -> None: await self._setup_state_group_id_seq() await self._setup_user_id_seq() await self._setup_events_stream_seqs() + await self._setup_sequence( + "un_partial_stated_event_stream_sequence", + ("un_partial_stated_event_stream",), + ) await self._setup_sequence( "device_inbox_sequence", ("device_inbox", "device_federation_outbox") ) @@ -779,6 +783,7 @@ def alter_table(txn: LoggingTransaction) -> None: await self._setup_sequence("receipts_sequence", ("receipts_linearized",)) await self._setup_sequence("presence_stream_sequence", ("presence_stream",)) await self._setup_auth_chain_sequence() + await self._setup_application_services_sequence() # Step 3. Get tables. self.progress.set_state("Fetching tables") @@ -1133,6 +1138,27 @@ def r(txn: LoggingTransaction) -> None: r, ) + async def _setup_application_services_sequence(self) -> None: + curr_tnx_id: Optional[ + int + ] = await self.sqlite_store.db_pool.simple_select_one_onecol( + table="application_services_txns", + keyvalues={}, + retcol="COALESCE(max(txn_id), 0)", + ) + + def r(txn: LoggingTransaction) -> None: + txn.execute( + "ALTER SEQUENCE application_services_txn_id_seq RESTART WITH %s", + (curr_tnx_id + 1,), + ) + + if curr_tnx_id is not None: + await self.postgres_store.db_pool.runInteraction( + "_setup_application_services_sequence", + r, + ) + ############################################## # The following is simply UI stuff