FIX: Reset flair group if user is removed from group (#17862)

The flair used to stay set even if the user was removed from the group.
This commit is contained in:
Bianca Nenciu
2022-08-12 15:45:09 +03:00
committed by GitHub
parent 69664d2153
commit 4b70594173
3 changed files with 27 additions and 6 deletions
@@ -0,0 +1,16 @@
# frozen_string_literal: true
class ResetFlairGroupIdIfNotGroupMember < ActiveRecord::Migration[7.0]
def change
execute <<~SQL
UPDATE users
SET flair_group_id = NULL
WHERE flair_group_id IS NOT NULL AND NOT EXISTS (
SELECT 1
FROM group_users
WHERE group_users.user_id = users.id
AND group_users.group_id = users.flair_group_id
)
SQL
end
end