Last active
May 23, 2020 09:48
-
-
Save rgpublic/0b7c44afafae71a8cc44732a5c217936 to your computer and use it in GitHub Desktop.
Delete room
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool. Much better. Changed my GIST.