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

Commit

Permalink
Fix support for SQLite 3.7.
Browse files Browse the repository at this point in the history
Partial indices support was added in 3.8.0, so we need to use the
background updates that handles this correctly.
  • Loading branch information
erikjohnston committed Dec 9, 2019
1 parent 0f3614f commit 4cade96
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
16 changes: 16 additions & 0 deletions synapse/storage/data_stores/main/events_bg_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,22 @@ def __init__(self, database: Database, db_conn, hs):
"event_store_labels", self._event_store_labels
)

self.db.updates.register_background_index_update(
"redactions_have_censored_idx",
index_name="redactions_have_censored",
table="redactions",
columns=["event_id"],
where_clause="NOT have_censored",
)

self.db.updates.register_background_index_update(
"redactions_have_censored_ts_idx",
index_name="redactions_have_censored_ts",
table="redactions",
columns=["received_ts"],
where_clause="NOT have_censored",
)

@defer.inlineCallbacks
def _background_reindex_fields_sender(self, progress, batch_size):
target_min_stream_id = progress["target_min_stream_id_inclusive"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@
*/

ALTER TABLE redactions ADD COLUMN have_censored BOOL NOT NULL DEFAULT false;
CREATE INDEX redactions_have_censored ON redactions(event_id) WHERE not have_censored;

INSERT INTO background_updates (update_name, progress_json) VALUES
('redactions_have_censored_idx', '{}');
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
*/

ALTER TABLE redactions ADD COLUMN received_ts BIGINT;
CREATE INDEX redactions_have_censored_ts ON redactions(received_ts) WHERE not have_censored;

INSERT INTO background_updates (update_name, progress_json) VALUES
('redactions_received_ts', '{}');

INSERT INTO background_updates (update_name, progress_json) VALUES
('redactions_have_censored_ts_idx', '{}');

0 comments on commit 4cade96

Please sign in to comment.