-- Replace your whitelist here
WITH keep_users AS (
    SELECT unnest(ARRAY[
        '@jan:freedombox.be',
        '@yves:freedombox.be',
        '@sarah:freedombox.be',
        '@lisa:freedombox.be',
        '@ignas:freedombox.be',
        '@brecht:freedombox.be'
    ]) AS name
)

-- 1. Delete from users table
DELETE FROM users
WHERE name NOT IN (SELECT name FROM keep_users);

-- 2. Delete from events table (roughly by sender)
DELETE FROM events
WHERE sender NOT IN (SELECT name FROM keep_users);

-- 3. Delete from account_data
DELETE FROM account_data
WHERE user_id NOT IN (SELECT name FROM keep_users);

-- 4. Delete from devices
DELETE FROM devices
WHERE user_id NOT IN (SELECT name FROM keep_users);

-- 5. Delete from room_memberships (rough)
DELETE FROM room_memberships
WHERE user_id NOT IN (SELECT name FROM keep_users);

-- 6. Delete from other per-user tables (examples)
DELETE FROM presence_stream
WHERE user_id NOT IN (SELECT name FROM keep_users);

DELETE FROM user_ips
WHERE user_id NOT IN (SELECT name FROM keep_users);

DELETE FROM pushers
WHERE user_id NOT IN (SELECT name FROM keep_users);

DELETE FROM account_validity
WHERE user_id NOT IN (SELECT name FROM keep_users);

-- Add more tables if necessary

