From 9af44d22208613872ca4d91716b50045ddb189a4 Mon Sep 17 00:00:00 2001
From: Toastie <toastie@toastiet0ast.com>
Date: Fri, 14 Mar 2025 13:34:15 +1300
Subject: [PATCH] fixed unrole timer cleanup migration

---
 src/EllieBot/Migrations/Sqlite/20250126062816_cleanup.sql | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/EllieBot/Migrations/Sqlite/20250126062816_cleanup.sql b/src/EllieBot/Migrations/Sqlite/20250126062816_cleanup.sql
index 1e361d4..df8efd3 100644
--- a/src/EllieBot/Migrations/Sqlite/20250126062816_cleanup.sql
+++ b/src/EllieBot/Migrations/Sqlite/20250126062816_cleanup.sql
@@ -1,4 +1,4 @@
-BEGIN TRANSACTION;
+BEGIN TRANSACTION;
 
 DROP INDEX "IX_XpSettings_GuildConfigId";
 
@@ -142,7 +142,8 @@ DELETE FROM VcRoleInfo WHERE GuildConfigId IS NULL OR GuildConfigId NOT IN (SELE
 UPDATE VcRoleInfo
 SET GuildId = (SELECT GuildId FROM GuildConfigs WHERE GuildConfigs.Id = VcRoleInfo.GuildConfigId);
 
-DELETE FROM UnroleTimer WHERE GuildConfigId IS NULL OR GuildConfigId NOT IN (SELECT Id FROM GuildConfigs);
+DELETE FROM UnroleTimer WHERE GuildConfigId IS NULL OR GuildConfigId NOT IN (SELECT Id FROM GuildConfigs)
+    OR (GuildId, UserId) IN (SELECT GuildId, UserId FROM UnroleTimer GROUP BY GuildId, UserId HAVING COUNT(*) > 1);
 UPDATE UnroleTimer
 SET GuildId = (SELECT GuildId FROM GuildConfigs WHERE GuildConfigs.Id = UnroleTimer.GuildConfigId);