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

Commit

Permalink
Fix port script fails when DB has no backfilled events. (#8729)
Browse files Browse the repository at this point in the history
Fixes #8618
  • Loading branch information
erikjohnston committed Nov 11, 2020
1 parent 5829872 commit 41a3899
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog.d/8729.bugfix
@@ -0,0 +1 @@
Fix port script fails when DB has no backfilled events. Broke in v1.21.0.
12 changes: 5 additions & 7 deletions scripts/synapse_port_db
Expand Up @@ -876,14 +876,12 @@ class Porter(object):
"ALTER SEQUENCE events_stream_seq RESTART WITH %s", (next_id,)
)

txn.execute("SELECT -MIN(stream_ordering) FROM events")
txn.execute("SELECT GREATEST(-MIN(stream_ordering), 1) FROM events")
curr_id = txn.fetchone()[0]
if curr_id:
next_id = curr_id + 1
txn.execute(
"ALTER SEQUENCE events_backfill_stream_seq RESTART WITH %s",
(next_id,),
)
next_id = curr_id + 1
txn.execute(
"ALTER SEQUENCE events_backfill_stream_seq RESTART WITH %s", (next_id,),
)

return self.postgres_store.db_pool.runInteraction(
"_setup_events_stream_seqs", r
Expand Down

0 comments on commit 41a3899

Please sign in to comment.