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

Commit 41a3899

Browse files
authored
Fix port script fails when DB has no backfilled events. (#8729)
Fixes #8618
1 parent 5829872 commit 41a3899

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

changelog.d/8729.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix port script fails when DB has no backfilled events. Broke in v1.21.0.

scripts/synapse_port_db

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -876,14 +876,12 @@ class Porter(object):
876876
"ALTER SEQUENCE events_stream_seq RESTART WITH %s", (next_id,)
877877
)
878878

879-
txn.execute("SELECT -MIN(stream_ordering) FROM events")
879+
txn.execute("SELECT GREATEST(-MIN(stream_ordering), 1) FROM events")
880880
curr_id = txn.fetchone()[0]
881-
if curr_id:
882-
next_id = curr_id + 1
883-
txn.execute(
884-
"ALTER SEQUENCE events_backfill_stream_seq RESTART WITH %s",
885-
(next_id,),
886-
)
881+
next_id = curr_id + 1
882+
txn.execute(
883+
"ALTER SEQUENCE events_backfill_stream_seq RESTART WITH %s", (next_id,),
884+
)
887885

888886
return self.postgres_store.db_pool.runInteraction(
889887
"_setup_events_stream_seqs", r

0 commit comments

Comments
 (0)