Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration to clean up bogus rooms #267

Merged
merged 4 commits into from
Aug 23, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions state/migrations/20230822174049_bogus_snapshot_cleanup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
-- +goose Up
-- This migration runs a one-time cleanup job to delete rooms with dodgy state snapshots.
-- A room is dodgy if its current snapshot lacks a create event.
BEGIN;

CREATE TEMPORARY TABLE bogus_rooms AS (
SELECT room_id, current_snapshot_id
FROM syncv3_rooms
WHERE room_id NOT IN (
SELECT room_id
FROM syncv3_events
WHERE event_type = 'm.room.create'
AND state_key = ''
)
);

DELETE
FROM syncv3_events
WHERE room_id IN (SELECT room_id FROM bogus_rooms);

DELETE
FROM syncv3_snapshots
WHERE room_id IN (SELECT room_id FROM bogus_rooms);

DELETE
FROM syncv3_rooms
WHERE room_id IN (SELECT room_id FROM bogus_rooms);

COMMIT;

-- +goose Down
-- downgrading is a no-op.