From 6bbeb005f512d36f28c18f4e784182bd385c7af7 Mon Sep 17 00:00:00 2001 From: Pranav Raj S Date: Thu, 18 Feb 2021 15:56:54 +0530 Subject: [PATCH] fix: Remove orphan members from inbox (#1797) --- ...4129_remove_orphan_inbox_members_from_inboxes.rb | 13 +++++++++++++ db/schema.rb | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20210217154129_remove_orphan_inbox_members_from_inboxes.rb diff --git a/db/migrate/20210217154129_remove_orphan_inbox_members_from_inboxes.rb b/db/migrate/20210217154129_remove_orphan_inbox_members_from_inboxes.rb new file mode 100644 index 000000000..6dbd89ce8 --- /dev/null +++ b/db/migrate/20210217154129_remove_orphan_inbox_members_from_inboxes.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 8b7476907..a9bf11747 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # 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 enable_extension "pg_stat_statements"