summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2020-11-11 15:08:03 +0000
committerGitHub <noreply@github.com>2020-11-11 15:08:03 +0000
commit41a389934e45dd2a9e96b0b465626adef18b25b8 (patch)
tree692b6ecb83ce73fe7e3e5280821016f420c062c6
parentFix port script to handle foreign key constraints (#8730) (diff)
downloadsynapse-41a389934e45dd2a9e96b0b465626adef18b25b8.tar.xz
Fix port script fails when DB has no backfilled events. (#8729)
Fixes #8618
-rw-r--r--changelog.d/8729.bugfix1
-rwxr-xr-xscripts/synapse_port_db12
2 files changed, 6 insertions, 7 deletions
diff --git a/changelog.d/8729.bugfix b/changelog.d/8729.bugfix
new file mode 100644
index 0000000000..7f59a3b9e2
--- /dev/null
+++ b/changelog.d/8729.bugfix
@@ -0,0 +1 @@
+Fix port script fails when DB has no backfilled events. Broke in v1.21.0.
diff --git a/scripts/synapse_port_db b/scripts/synapse_port_db
index 7a638ea8e3..604b961bd2 100755
--- a/scripts/synapse_port_db
+++ b/scripts/synapse_port_db
@@ -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