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
@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