From 162e2c1ce5171c5794f81f1668345bfe7caa6108 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 18 Nov 2015 15:54:50 +0000 Subject: [PATCH 1/2] Fix database port script to work with new event_search table --- scripts/synapse_port_db | 55 ++++++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/scripts/synapse_port_db b/scripts/synapse_port_db index 62515997b102..c0da2af230e0 100755 --- a/scripts/synapse_port_db +++ b/scripts/synapse_port_db @@ -68,6 +68,7 @@ APPEND_ONLY_TABLES = [ "state_groups_state", "event_to_state_groups", "rejections", + "event_search", ] @@ -229,19 +230,51 @@ class Porter(object): if rows: next_chunk = rows[-1][0] + 1 - self._convert_rows(table, headers, rows) + if table == "event_search": + # We have to treat event_search differnetly since it has a + # different structure in the two different databases. + def insert(txn): + sql = ( + "INSERT INTO event_search (event_id, room_id, key, sender, vector)" + " VALUES (?,?,?,?,to_tsvector('english', ?))" + ) - def insert(txn): - self.postgres_store.insert_many_txn( - txn, table, headers[1:], rows - ) + rows_dict = [ + dict(zip(headers, row)) + for row in rows + ] + + txn.executemany(sql, [ + ( + row["event_id"], + row["room_id"], + row["key"], + row["sender"], + row["value"], + ) + for row in rows_dict + ]) + + self.postgres_store._simple_update_one_txn( + txn, + table="port_from_sqlite3", + keyvalues={"table_name": table}, + updatevalues={"rowid": next_chunk}, + ) + else: + self._convert_rows(table, headers, rows) - self.postgres_store._simple_update_one_txn( - txn, - table="port_from_sqlite3", - keyvalues={"table_name": table}, - updatevalues={"rowid": next_chunk}, - ) + def insert(txn): + self.postgres_store.insert_many_txn( + txn, table, headers[1:], rows + ) + + self.postgres_store._simple_update_one_txn( + txn, + table="port_from_sqlite3", + keyvalues={"table_name": table}, + updatevalues={"rowid": next_chunk}, + ) yield self.postgres_store.execute(insert) From b36144073864b20e465e4db4e261476b0fe021f4 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 19 Nov 2015 09:11:42 +0000 Subject: [PATCH 2/2] Spelling --- scripts/synapse_port_db | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/synapse_port_db b/scripts/synapse_port_db index c0da2af230e0..d4772fcf6ee2 100755 --- a/scripts/synapse_port_db +++ b/scripts/synapse_port_db @@ -231,7 +231,7 @@ class Porter(object): next_chunk = rows[-1][0] + 1 if table == "event_search": - # We have to treat event_search differnetly since it has a + # We have to treat event_search differently since it has a # different structure in the two different databases. def insert(txn): sql = (