guilds: properly delete child channels on guild delete

This commit is contained in:
Luna 2021-09-05 23:29:35 -03:00
parent 1d36038469
commit 7e79abf344
1 changed files with 16 additions and 0 deletions

View File

@ -232,6 +232,22 @@ async def _del_from_table(table: str, user_id: int):
async def delete_guild(guild_id: int): async def delete_guild(guild_id: int):
"""Delete a single guild.""" """Delete a single guild."""
await _del_from_table("vanity_invites", guild_id) await _del_from_table("vanity_invites", guild_id)
# while most guild channel tables have 'ON DELETE CASCADE', this
# must not be true to the channels table, which is generic for any channel.
#
# the drawback is that this causes breakdown on the data's semantics as
# we get a channel with a type of GUILD_TEXT/GUILD_VOICE but without any
# entry on the guild_channels table, causing errors.
for channel_id in await app.storage.get_channel_ids(guild_id):
await app.db.execute(
"""
DELETE FROM channels
WHERE channels.id = $1
""",
channel_id,
)
await app.db.execute( await app.db.execute(
""" """
DELETE FROM guilds DELETE FROM guilds