Skip to content

Instantly share code, notes, and snippets.

@rgpublic
Last active May 23, 2020 09:48
Show Gist options
  • Save rgpublic/0b7c44afafae71a8cc44732a5c217936 to your computer and use it in GitHub Desktop.
Save rgpublic/0b7c44afafae71a8cc44732a5c217936 to your computer and use it in GitHub Desktop.
Delete room
#!/bin/bash
## CAUTION:
## This script will remove (hopefully) all trace of the given room ID from
## your homeserver.db
## Do not run it lightly.
set -e
if [ "$1" == "" ]; then
echo "Usage delete_room <room_id>"
exit
fi
ROOMID="'\''$1'\''";
r=`su postgres -c "psql synapse -A -t -c 'SELECT COUNT(*) from rooms WHERE room_id=$ROOMID'"`
if [ "$r" != "1" ]; then
echo "Room not found.";
exit;
fi;
su postgres -c "psql synapse -A -t -c \"select table_name from information_schema.columns where column_name = 'room_id'\"" | while read table ; do
cnt_some=`su postgres -c "psql synapse -A -t -c 'SELECT COUNT(*) FROM $table WHERE room_id=$ROOMID'"`
cnt_total=`su postgres -c "psql synapse -A -t -c 'SELECT COUNT(*) FROM $table'"`
echo "$table (Deleting $cnt_some/$cnt_total rows)"
su postgres -c "psql synapse -A -t -c 'DELETE FROM $table WHERE room_id=$ROOMID'"
done
@elhil
Copy link

elhil commented Jan 17, 2020

Running select table_name from information_schema.columns where column_name = 'room_id'; in postgres gives me this list:

    "state_groups" \
    "state_groups_state" \
    "appservice_room_list" \
    "blocked_rooms" \
    "current_state_delta_stream" \
    "e2e_room_keys" \
    "event_auth" \
    "event_backward_extremities" \
    "event_edges" \
    "event_forward_extremities" \
    "event_json" \
    "event_push_actions" \
    "event_push_summary" \
    "event_reports" \
    "event_search" \
    "events" \
    "group_rooms" \
    "group_summary_rooms" \
    "local_invites" \
    "public_room_list_stream" \
    "pusher_throttle" \
    "receipts_graph" \
    "receipts_linearized" \
    "room_account_data" \
    "room_aliases" \
    "room_depth" \
    "room_memberships" \
    "room_stats_earliest_token" \
    "room_tags" \
    "room_tags_revisions" \
    "rooms" \
    "state_events" \
    "stream_ordering_to_exterm" \
    "user_directory" \
    "users_in_public_rooms" \
    "users_who_share_private_rooms" \
    "current_state_events" \
    "event_labels" \
    "room_retention" \
    "room_stats_current" \
    "room_stats_historical" \
    "room_stats_state" \

@rgpublic
Copy link
Author

Cool. Much better. Changed my GIST.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment