summary refs log tree commit diff
path: root/synapse/storage/schema
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2023-06-07 10:50:32 +0100
committerGitHub <noreply@github.com>2023-06-07 10:50:32 +0100
commita701c089fa2a345243985a765506a52b50e50963 (patch)
tree6add82a98f13d83ff0123aea32e166a30aabd9c3 /synapse/storage/schema
parentFixup changelog (diff)
downloadsynapse-a701c089fa2a345243985a765506a52b50e50963.tar.xz
Fix schema delta error in 1.85 (#15738)
There appears to be a race where you can end up with entries in
`event_push_summary` with both a `NULL` and `main` thread ID.

Fixes #15736

Introduced in #15597
Diffstat (limited to 'synapse/storage/schema')
-rw-r--r--synapse/storage/schema/main/delta/77/05thread_notifications_backfill.sql8
1 files changed, 8 insertions, 0 deletions
diff --git a/synapse/storage/schema/main/delta/77/05thread_notifications_backfill.sql b/synapse/storage/schema/main/delta/77/05thread_notifications_backfill.sql
index ce6f9ff937..b09aa817ae 100644
--- a/synapse/storage/schema/main/delta/77/05thread_notifications_backfill.sql
+++ b/synapse/storage/schema/main/delta/77/05thread_notifications_backfill.sql
@@ -21,6 +21,14 @@ DELETE FROM background_updates WHERE update_name = 'event_push_backfill_thread_i
 -- Overwrite any null thread_id values.
 UPDATE event_push_actions_staging SET thread_id = 'main' WHERE thread_id IS NULL;
 UPDATE event_push_actions SET thread_id = 'main' WHERE thread_id IS NULL;
+
+-- Empirically we can end up with entries in the push summary table with both a
+-- `NULL` and `main` thread ID, which causes the update below to fail. We fudge
+-- this by deleting any `NULL` rows that have a corresponding `main`.
+DELETE FROM event_push_summary AS a WHERE thread_id IS NULL AND EXISTS (
+    SELECT 1 FROM event_push_summary AS b
+    WHERE b.thread_id = 'main' AND a.user_id = b.user_id AND a.room_id = b.room_id
+);
 UPDATE event_push_summary SET thread_id = 'main' WHERE thread_id IS NULL;
 
 -- Drop the background updates to calculate the indexes used to find null thread_ids.