refactor purge to use foreign key cascade

This commit is contained in:
Infinidoge 2024-12-31 18:19:11 -05:00
parent f3b40986be
commit d7863f2a49
Signed by: Infinidoge
SSH key fingerprint: SHA256:GT2StvPQMMfFHyiiFJymQxfTG/z6EWLJ6NWItf5K5sA

View file

@ -37,14 +37,8 @@ You may want to `{ctx.clean_prefix}nomen export` first"""
to_purge = await confirm(ctx, msg) to_purge = await confirm(ctx, msg)
if to_purge: if to_purge:
await self.bot.db.execute( # Foreign key constraints will automatically cascade to delete dependent data
""" await self.bot.db.execute("DELETE FROM users WHERE user_id=?", (ctx.author.id,))
DELETE FROM keywords WHERE user_id=?;
DELETE FROM users WHERE user_id=?;
DELETE FROM user_ignores WHERE user_id=?;
""",
(ctx.author.id,),
)
await self.bot.db.commit() await self.bot.db.commit()
await ctx.send("Deleted all user data.") await ctx.send("Deleted all user data.")
else: else: