Skip to content
Snippets Groups Projects
Commit e5d91b8e authored by Erik Johnston's avatar Erik Johnston
Browse files

Merge pull request #387 from matrix-org/erikj/fix_port_script

Fix database port script to work with new event_search table
parents f0ee1d51 b3614407
No related branches found
No related tags found
No related merge requests found
...@@ -68,6 +68,7 @@ APPEND_ONLY_TABLES = [ ...@@ -68,6 +68,7 @@ APPEND_ONLY_TABLES = [
"state_groups_state", "state_groups_state",
"event_to_state_groups", "event_to_state_groups",
"rejections", "rejections",
"event_search",
] ]
...@@ -229,19 +230,51 @@ class Porter(object): ...@@ -229,19 +230,51 @@ class Porter(object):
if rows: if rows:
next_chunk = rows[-1][0] + 1 next_chunk = rows[-1][0] + 1
self._convert_rows(table, headers, rows) if table == "event_search":
# We have to treat event_search differently 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): rows_dict = [
self.postgres_store.insert_many_txn( dict(zip(headers, row))
txn, table, headers[1:], rows 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( def insert(txn):
txn, self.postgres_store.insert_many_txn(
table="port_from_sqlite3", txn, table, headers[1:], rows
keyvalues={"table_name": table}, )
updatevalues={"rowid": next_chunk},
) 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) yield self.postgres_store.execute(insert)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment