From 28d96cb2b49c12b741d03e4b74f30f8910f9942b Mon Sep 17 00:00:00 2001 From: David Robertson Date: Mon, 11 Jul 2022 10:36:18 +0100 Subject: [PATCH] Ensure portdb selects _all_ rows with negative rowids (#13226) --- changelog.d/13226.bugfix | 1 + synapse/_scripts/synapse_port_db.py | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 changelog.d/13226.bugfix diff --git a/changelog.d/13226.bugfix b/changelog.d/13226.bugfix new file mode 100644 index 000000000..df96d41f3 --- /dev/null +++ b/changelog.d/13226.bugfix @@ -0,0 +1 @@ +Fix a long-standing bug where the `synapse_port_db` script could fail to copy rows with negative row ids. diff --git a/synapse/_scripts/synapse_port_db.py b/synapse/_scripts/synapse_port_db.py index 642fd4162..26834a437 100755 --- a/synapse/_scripts/synapse_port_db.py +++ b/synapse/_scripts/synapse_port_db.py @@ -418,12 +418,15 @@ class Porter: self.progress.update(table, table_size) # Mark table as done return + # We sweep over rowids in two directions: one forwards (rowids 1, 2, 3, ...) + # and another backwards (rowids 0, -1, -2, ...). forward_select = ( "SELECT rowid, * FROM %s WHERE rowid >= ? ORDER BY rowid LIMIT ?" % (table,) ) backward_select = ( - "SELECT rowid, * FROM %s WHERE rowid <= ? ORDER BY rowid LIMIT ?" % (table,) + "SELECT rowid, * FROM %s WHERE rowid <= ? ORDER BY rowid DESC LIMIT ?" + % (table,) ) do_forward = [True]