Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Update synapse_port_db for new sequences #15965

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/15965.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix `synapse_port_db` not configuring the `application_services_txns` and `un_partial_stated_event_stream_sequence` sequences. Contributed by @vanguacamolie.
26 changes: 26 additions & 0 deletions synapse/_scripts/synapse_port_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
Expand All @@ -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")
Expand Down Expand Up @@ -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(
Comment on lines +1142 to +1144
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this ever really None since we have the coalesce?

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,
)
Comment on lines +1150 to +1160
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will fix the mypy issue:

Suggested change
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,
)
if curr_tnx_id is not None:
def r(txn: LoggingTransaction) -> None:
txn.execute(
"ALTER SEQUENCE application_services_txn_id_seq RESTART WITH %s",
(curr_tnx_id + 1,),
)
await self.postgres_store.db_pool.runInteraction(
"_setup_application_services_sequence",
r,
)



##############################################
# The following is simply UI stuff
Expand Down