fix: Remove orphan members from inbox (#1797)

This commit is contained in:
Pranav Raj S 2021-02-18 15:56:54 +05:30 committed by GitHub
parent 5daf970a87
commit 6bbeb005f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View file

@ -0,0 +1,13 @@
class RemoveOrphanInboxMembersFromInboxes < ActiveRecord::Migration[6.0]
def change
Account.all.map do |account|
user_ids = account.users.all.map(&:id)
inboxes = account.inboxes
inboxes.each do |inbox|
inbox.inbox_members.each do |inbox_member|
inbox_member.destroy! unless user_ids.include?(inbox_member.user_id)
end
end
end
end
end

View file

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_02_12_154240) do ActiveRecord::Schema.define(version: 2021_02_17_154129) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements" enable_extension "pg_stat_statements"