Skip to content

Commit

Permalink
Add migration to cleanup dead invites
Browse files Browse the repository at this point in the history
Fixes #350.
  • Loading branch information
David Robertson committed Oct 19, 2023
1 parent 867cf68 commit b4f30f5
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions state/migrations/20231019153023_cleanup_dead_invites.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- +goose Up
-- +goose StatementBegin
WITH
dead_invites(user_id, room_id) AS (
SELECT syncv3_invites.user_id, syncv3_invites.room_id
FROM syncv3_invites
JOIN syncv3_rooms USING (room_id)
JOIN syncv3_snapshots ON (syncv3_snapshots.snapshot_id = syncv3_rooms.current_snapshot_id)
JOIN syncv3_events ON (
event_nid = ANY (membership_events)
AND state_key = syncv3_invites.user_id
AND NOT (membership = 'invite' OR membership = '_invite')
)
)
DELETE FROM syncv3_invites
WHERE (user_id, room_id) IN (SELECT * FROM dead_invites);
-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin
-- no-op
-- +goose StatementEnd

0 comments on commit b4f30f5

Please sign in to comment.