From 2202986a2f884875c1932dc6ecf3280363fe99af Mon Sep 17 00:00:00 2001 From: Nat Date: Fri, 2 Aug 2024 18:27:18 +0800 Subject: [PATCH] DEV: Avoid subquery in the ensure-consistency onceoff --- db/post_migrate/20240711102255_ensure_consistency.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/db/post_migrate/20240711102255_ensure_consistency.rb b/db/post_migrate/20240711102255_ensure_consistency.rb index 41a4c72..b14ea7e 100644 --- a/db/post_migrate/20240711102255_ensure_consistency.rb +++ b/db/post_migrate/20240711102255_ensure_consistency.rb @@ -27,7 +27,9 @@ def up # delete votes associated with no user DB.exec(<<~SQL) DELETE FROM topic_voting_votes - WHERE user_id NOT IN (SELECT id FROM users) + USING topic_voting_votes tvv + LEFT JOIN users u ON tvv.user_id = u.id + WHERE u.id IS NULL; SQL # delete votes associated with no topics