From 4f227e1d0ad24aadfc7e1169e4f62f516ec62810 Mon Sep 17 00:00:00 2001
From: Tor Andersson <tor@ccxvii.net>
Date: Thu, 11 Jan 2024 18:23:06 +0100
Subject: Send chat message when a user leaves games by deleting their account.

---
 schema.sql | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

(limited to 'schema.sql')

diff --git a/schema.sql b/schema.sql
index f04425f..02b9dff 100644
--- a/schema.sql
+++ b/schema.sql
@@ -618,8 +618,9 @@ begin
 	delete from threads where author_id = old.user_id;
 	delete from game_chat where user_id = old.user_id;
 	delete from ratings where user_id = old.user_id;
-	update games set owner_id = 0 where owner_id = old.user_id;
+	delete from players where user_id = old.user_id and game_id in (select game_id from games where status <= 1);
 	update players set user_id = 0 where user_id = old.user_id;
+	update games set owner_id = 0 where owner_id = old.user_id;
 end;
 
 drop trigger if exists trigger_delete_on_threads;
-- 
cgit v1.2.3

