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

Commit f7c6553

Browse files
authored
Fix schema delta error in 1.85 (#15739)
Some users seem to have multiple rows per user / room with a null thread ID, which we need to handle.
1 parent 7acf7f2 commit f7c6553

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

changelog.d/15739.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bug in schema delta that broke upgrades for some deployments. Introduced in v1.85.0.

synapse/storage/schema/main/delta/77/05thread_notifications_backfill.sql

+14-2
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,25 @@ UPDATE event_push_actions_staging SET thread_id = 'main' WHERE thread_id IS NULL
2323
UPDATE event_push_actions SET thread_id = 'main' WHERE thread_id IS NULL;
2424

2525
-- Empirically we can end up with entries in the push summary table with both a
26-
-- `NULL` and `main` thread ID, which causes the update below to fail. We fudge
26+
-- `NULL` and `main` thread ID, which causes the insert below to fail. We fudge
2727
-- this by deleting any `NULL` rows that have a corresponding `main`.
2828
DELETE FROM event_push_summary AS a WHERE thread_id IS NULL AND EXISTS (
2929
SELECT 1 FROM event_push_summary AS b
3030
WHERE b.thread_id = 'main' AND a.user_id = b.user_id AND a.room_id = b.room_id
3131
);
32-
UPDATE event_push_summary SET thread_id = 'main' WHERE thread_id IS NULL;
32+
-- Copy the NULL threads to have a 'main' thread ID.
33+
--
34+
-- Note: Some people seem to have duplicate rows with a `NULL` thread ID, in
35+
-- which case we just fudge it with using MAX of the values. The counts *may* be
36+
-- wrong for such rooms, but a) its an edge case, and b) they'll be fixed when
37+
-- the user reads the room.
38+
INSERT INTO event_push_summary (user_id, room_id, notif_count, stream_ordering, unread_count, last_receipt_stream_ordering, thread_id)
39+
SELECT user_id, room_id, MAX(notif_count), MAX(stream_ordering), MAX(unread_count), MAX(last_receipt_stream_ordering), 'main'
40+
FROM event_push_summary
41+
WHERE thread_id IS NULL
42+
GROUP BY user_id, room_id, thread_id;
43+
44+
DELETE FROM event_push_summary AS a WHERE thread_id IS NULL;
3345

3446
-- Drop the background updates to calculate the indexes used to find null thread_ids.
3547
DELETE FROM background_updates WHERE update_name = 'event_push_actions_thread_id_null';

0 commit comments

Comments
 (0)