diff --git a/app/models/account.rb b/app/models/account.rb index 8ce2a4beb..d16194e40 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -32,40 +32,40 @@ class Account < ApplicationRecord validates :name, presence: true validates :auto_resolve_duration, numericality: { greater_than_or_equal_to: 1, allow_nil: true } - has_many :account_users, dependent: :destroy - has_many :agent_bot_inboxes, dependent: :destroy - has_many :agent_bots, dependent: :destroy - has_many :csat_survey_responses, dependent: :destroy - has_many :data_imports, dependent: :destroy + has_many :account_users, dependent: :destroy_async + has_many :agent_bot_inboxes, dependent: :destroy_async + has_many :agent_bots, dependent: :destroy_async + has_many :csat_survey_responses, dependent: :destroy_async + has_many :data_imports, dependent: :destroy_async has_many :users, through: :account_users - has_many :inboxes, dependent: :destroy - has_many :notes, dependent: :destroy - has_many :campaigns, dependent: :destroy - has_many :conversations, dependent: :destroy - has_many :messages, dependent: :destroy - has_many :contacts, dependent: :destroy - has_many :facebook_pages, dependent: :destroy, class_name: '::Channel::FacebookPage' - has_many :telegram_bots, dependent: :destroy - has_many :twilio_sms, dependent: :destroy, class_name: '::Channel::TwilioSms' - has_many :twitter_profiles, dependent: :destroy, class_name: '::Channel::TwitterProfile' - has_many :web_widgets, dependent: :destroy, class_name: '::Channel::WebWidget' - has_many :email_channels, dependent: :destroy, class_name: '::Channel::Email' - has_many :api_channels, dependent: :destroy, class_name: '::Channel::Api' - has_many :line_channels, dependent: :destroy, class_name: '::Channel::Line' - has_many :telegram_channels, dependent: :destroy, class_name: '::Channel::Telegram' - has_many :whatsapp_channels, dependent: :destroy, class_name: '::Channel::Whatsapp' - has_many :canned_responses, dependent: :destroy - has_many :webhooks, dependent: :destroy - has_many :labels, dependent: :destroy - has_many :notification_settings, dependent: :destroy - has_many :hooks, dependent: :destroy, class_name: 'Integrations::Hook' - has_many :working_hours, dependent: :destroy - has_many :kbase_portals, dependent: :destroy, class_name: '::Kbase::Portal' - has_many :kbase_categories, dependent: :destroy, class_name: '::Kbase::Category' - has_many :kbase_articles, dependent: :destroy, class_name: '::Kbase::Article' - has_many :teams, dependent: :destroy - has_many :custom_filters, dependent: :destroy - has_many :custom_attribute_definitions, dependent: :destroy + has_many :inboxes, dependent: :destroy_async + has_many :notes, dependent: :destroy_async + has_many :campaigns, dependent: :destroy_async + has_many :conversations, dependent: :destroy_async + has_many :messages, dependent: :destroy_async + has_many :contacts, dependent: :destroy_async + has_many :facebook_pages, dependent: :destroy_async, class_name: '::Channel::FacebookPage' + has_many :telegram_bots, dependent: :destroy_async + has_many :twilio_sms, dependent: :destroy_async, class_name: '::Channel::TwilioSms' + has_many :twitter_profiles, dependent: :destroy_async, class_name: '::Channel::TwitterProfile' + has_many :web_widgets, dependent: :destroy_async, class_name: '::Channel::WebWidget' + has_many :email_channels, dependent: :destroy_async, class_name: '::Channel::Email' + has_many :api_channels, dependent: :destroy_async, class_name: '::Channel::Api' + has_many :line_channels, dependent: :destroy_async, class_name: '::Channel::Line' + has_many :telegram_channels, dependent: :destroy_async, class_name: '::Channel::Telegram' + has_many :whatsapp_channels, dependent: :destroy_async, class_name: '::Channel::Whatsapp' + has_many :canned_responses, dependent: :destroy_async + has_many :webhooks, dependent: :destroy_async + has_many :labels, dependent: :destroy_async + has_many :notification_settings, dependent: :destroy_async + has_many :hooks, dependent: :destroy_async, class_name: 'Integrations::Hook' + has_many :working_hours, dependent: :destroy_async + has_many :kbase_portals, dependent: :destroy_async, class_name: '::Kbase::Portal' + has_many :kbase_categories, dependent: :destroy_async, class_name: '::Kbase::Category' + has_many :kbase_articles, dependent: :destroy_async, class_name: '::Kbase::Article' + has_many :teams, dependent: :destroy_async + has_many :custom_filters, dependent: :destroy_async + has_many :custom_attribute_definitions, dependent: :destroy_async has_flags ACCOUNT_SETTINGS_FLAGS.merge(column: 'settings_flags').merge(DEFAULT_QUERY_SETTING) diff --git a/app/models/agent_bot.rb b/app/models/agent_bot.rb index 75f051f8e..beff22a22 100644 --- a/app/models/agent_bot.rb +++ b/app/models/agent_bot.rb @@ -23,10 +23,10 @@ class AgentBot < ApplicationRecord include AccessTokenable include Avatarable - has_many :agent_bot_inboxes, dependent: :destroy + has_many :agent_bot_inboxes, dependent: :destroy_async has_many :inboxes, through: :agent_bot_inboxes has_many :messages, as: :sender, dependent: :restrict_with_exception - belongs_to :account, dependent: :destroy, optional: true + belongs_to :account, dependent: :destroy_async, optional: true def available_name name diff --git a/app/models/concerns/access_tokenable.rb b/app/models/concerns/access_tokenable.rb index ae9aad2e5..0bb8daa4f 100644 --- a/app/models/concerns/access_tokenable.rb +++ b/app/models/concerns/access_tokenable.rb @@ -1,7 +1,7 @@ module AccessTokenable extend ActiveSupport::Concern included do - has_one :access_token, as: :owner, dependent: :destroy + has_one :access_token, as: :owner, dependent: :destroy_async after_create :create_access_token end diff --git a/app/models/concerns/channelable.rb b/app/models/concerns/channelable.rb index 76b18fc81..e60066d5f 100644 --- a/app/models/concerns/channelable.rb +++ b/app/models/concerns/channelable.rb @@ -3,7 +3,7 @@ module Channelable included do validates :account_id, presence: true belongs_to :account - has_one :inbox, as: :channel, dependent: :destroy + has_one :inbox, as: :channel, dependent: :destroy_async end def has_24_hour_messaging_window? diff --git a/app/models/concerns/out_of_offisable.rb b/app/models/concerns/out_of_offisable.rb index 53b466cdf..e22dd668c 100644 --- a/app/models/concerns/out_of_offisable.rb +++ b/app/models/concerns/out_of_offisable.rb @@ -6,7 +6,7 @@ module OutOfOffisable OFFISABLE_ATTRS = %w[day_of_week closed_all_day open_hour open_minutes close_hour close_minutes].freeze included do - has_many :working_hours, dependent: :destroy + has_many :working_hours, dependent: :destroy_async after_create :create_default_working_hours end diff --git a/app/models/concerns/reportable.rb b/app/models/concerns/reportable.rb index 3f230650f..9da1e93dc 100644 --- a/app/models/concerns/reportable.rb +++ b/app/models/concerns/reportable.rb @@ -4,6 +4,6 @@ module Reportable extend ActiveSupport::Concern included do - has_many :events, dependent: :destroy + has_many :events, dependent: :destroy_async end end diff --git a/app/models/contact.rb b/app/models/contact.rb index ec0b27d70..9ba3a4178 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -38,12 +38,12 @@ class Contact < ApplicationRecord format: { with: /\+[1-9]\d{1,14}\z/, message: 'should be in e164 format' } belongs_to :account - has_many :conversations, dependent: :destroy - has_many :contact_inboxes, dependent: :destroy - has_many :csat_survey_responses, dependent: :destroy + has_many :conversations, dependent: :destroy_async + has_many :contact_inboxes, dependent: :destroy_async + has_many :csat_survey_responses, dependent: :destroy_async has_many :inboxes, through: :contact_inboxes - has_many :messages, as: :sender, dependent: :destroy - has_many :notes, dependent: :destroy + has_many :messages, as: :sender, dependent: :destroy_async + has_many :notes, dependent: :destroy_async before_validation :prepare_email_attribute after_create_commit :dispatch_create_event, :ip_lookup diff --git a/app/models/contact_inbox.rb b/app/models/contact_inbox.rb index 6f36b8735..e87d30382 100644 --- a/app/models/contact_inbox.rb +++ b/app/models/contact_inbox.rb @@ -32,7 +32,7 @@ class ContactInbox < ApplicationRecord belongs_to :contact belongs_to :inbox - has_many :conversations, dependent: :destroy + has_many :conversations, dependent: :destroy_async def webhook_data { diff --git a/app/models/conversation.rb b/app/models/conversation.rb index a7a5b5b6d..c5cd30629 100644 --- a/app/models/conversation.rb +++ b/app/models/conversation.rb @@ -66,8 +66,8 @@ class Conversation < ApplicationRecord belongs_to :team, optional: true belongs_to :campaign, optional: true - has_many :messages, dependent: :destroy, autosave: true - has_one :csat_survey_response, dependent: :destroy + has_many :messages, dependent: :destroy_async, autosave: true + has_one :csat_survey_response, dependent: :destroy_async has_many :notifications, as: :primary_actor, dependent: :destroy before_save :ensure_snooze_until_reset diff --git a/app/models/inbox.rb b/app/models/inbox.rb index dbd64f820..ba85c9e64 100644 --- a/app/models/inbox.rb +++ b/app/models/inbox.rb @@ -39,19 +39,19 @@ class Inbox < ApplicationRecord belongs_to :channel, polymorphic: true, dependent: :destroy - has_many :campaigns, dependent: :destroy - has_many :contact_inboxes, dependent: :destroy + has_many :campaigns, dependent: :destroy_async + has_many :contact_inboxes, dependent: :destroy_async has_many :contacts, through: :contact_inboxes - has_many :inbox_members, dependent: :destroy + has_many :inbox_members, dependent: :destroy_async has_many :members, through: :inbox_members, source: :user - has_many :conversations, dependent: :destroy + has_many :conversations, dependent: :destroy_async has_many :messages, through: :conversations - has_one :agent_bot_inbox, dependent: :destroy + has_one :agent_bot_inbox, dependent: :destroy_async has_one :agent_bot, through: :agent_bot_inbox - has_many :webhooks, dependent: :destroy - has_many :hooks, dependent: :destroy, class_name: 'Integrations::Hook' + has_many :webhooks, dependent: :destroy_async + has_many :hooks, dependent: :destroy_async, class_name: 'Integrations::Hook' after_destroy :delete_round_robin_agents diff --git a/app/models/kbase/category.rb b/app/models/kbase/category.rb index a32331598..024efae8e 100644 --- a/app/models/kbase/category.rb +++ b/app/models/kbase/category.rb @@ -14,7 +14,7 @@ class Kbase::Category < ApplicationRecord belongs_to :account belongs_to :portal - has_many :folders, dependent: :destroy + has_many :folders, dependent: :destroy_async has_many :articles, dependent: :nullify before_validation :ensure_account_id diff --git a/app/models/kbase/portal.rb b/app/models/kbase/portal.rb index 5401361c4..03f8e29bf 100644 --- a/app/models/kbase/portal.rb +++ b/app/models/kbase/portal.rb @@ -20,9 +20,9 @@ # class Kbase::Portal < ApplicationRecord belongs_to :account - has_many :categories, dependent: :destroy + has_many :categories, dependent: :destroy_async has_many :folders, through: :categories - has_many :articles, dependent: :destroy + has_many :articles, dependent: :destroy_async validates :account_id, presence: true validates :name, presence: true diff --git a/app/models/message.rb b/app/models/message.rb index 920f338be..bd9c3c422 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -82,8 +82,8 @@ class Message < ApplicationRecord belongs_to :contact, required: false belongs_to :sender, polymorphic: true, required: false - has_many :attachments, dependent: :destroy, autosave: true, before_add: :validate_attachments_limit - has_one :csat_survey_response, dependent: :destroy + has_many :attachments, dependent: :destroy_async, autosave: true, before_add: :validate_attachments_limit + has_one :csat_survey_response, dependent: :destroy_async after_create_commit :execute_after_create_commit_callbacks diff --git a/app/models/platform_app.rb b/app/models/platform_app.rb index 2f7ec8e42..d8b2eb054 100644 --- a/app/models/platform_app.rb +++ b/app/models/platform_app.rb @@ -12,5 +12,5 @@ class PlatformApp < ApplicationRecord validates :name, presence: true - has_many :platform_app_permissibles, dependent: :destroy + has_many :platform_app_permissibles, dependent: :destroy_async end diff --git a/app/models/platform_app_permissible.rb b/app/models/platform_app_permissible.rb index c8efc59b4..14b804e84 100644 --- a/app/models/platform_app_permissible.rb +++ b/app/models/platform_app_permissible.rb @@ -22,5 +22,5 @@ class PlatformAppPermissible < ApplicationRecord validates :platform_app_id, uniqueness: { scope: [:permissible_id, :permissible_type] } belongs_to :platform_app - belongs_to :permissible, polymorphic: true, dependent: :destroy + belongs_to :permissible, polymorphic: true, dependent: :destroy_async end diff --git a/app/models/team.rb b/app/models/team.rb index 1b998eb4c..dd4713662 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -21,7 +21,7 @@ # class Team < ApplicationRecord belongs_to :account - has_many :team_members, dependent: :destroy + has_many :team_members, dependent: :destroy_async has_many :members, through: :team_members, source: :user has_many :conversations, dependent: :nullify diff --git a/app/models/telegram_bot.rb b/app/models/telegram_bot.rb index 2d8706753..8468e233f 100644 --- a/app/models/telegram_bot.rb +++ b/app/models/telegram_bot.rb @@ -12,6 +12,6 @@ class TelegramBot < ApplicationRecord belongs_to :account - has_one :inbox, as: :channel, dependent: :destroy + has_one :inbox, as: :channel, dependent: :destroy_async validates_uniqueness_of :auth_key, scope: :account_id end diff --git a/app/models/user.rb b/app/models/user.rb index 6f5e67bee..c73aad20c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -67,7 +67,7 @@ class User < ApplicationRecord validates :email, :name, presence: true validates_length_of :name, minimum: 1 - has_many :account_users, dependent: :destroy + has_many :account_users, dependent: :destroy_async has_many :accounts, through: :account_users accepts_nested_attributes_for :account_users @@ -75,18 +75,18 @@ class User < ApplicationRecord alias_attribute :conversations, :assigned_conversations has_many :csat_survey_responses, foreign_key: 'assigned_agent_id', dependent: :nullify - has_many :inbox_members, dependent: :destroy + has_many :inbox_members, dependent: :destroy_async has_many :inboxes, through: :inbox_members, source: :inbox has_many :messages, as: :sender has_many :invitees, through: :account_users, class_name: 'User', foreign_key: 'inviter_id', source: :inviter, dependent: :nullify - has_many :notifications, dependent: :destroy - has_many :notification_settings, dependent: :destroy - has_many :notification_subscriptions, dependent: :destroy - has_many :team_members, dependent: :destroy + has_many :notifications, dependent: :destroy_async + has_many :notification_settings, dependent: :destroy_async + has_many :notification_subscriptions, dependent: :destroy_async + has_many :team_members, dependent: :destroy_async has_many :teams, through: :team_members has_many :notes, dependent: :nullify - has_many :custom_filters, dependent: :destroy + has_many :custom_filters, dependent: :destroy_async before_validation :set_password_and_uid, on: :create diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index cef952cf8..20ebf4bfd 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -8,17 +8,17 @@ RSpec.describe Account do it { is_expected.to have_many(:users).through(:account_users) } it { is_expected.to have_many(:account_users) } - it { is_expected.to have_many(:inboxes).dependent(:destroy) } - it { is_expected.to have_many(:conversations).dependent(:destroy) } - it { is_expected.to have_many(:contacts).dependent(:destroy) } - it { is_expected.to have_many(:telegram_bots).dependent(:destroy) } - it { is_expected.to have_many(:canned_responses).dependent(:destroy) } - it { is_expected.to have_many(:facebook_pages).class_name('::Channel::FacebookPage').dependent(:destroy) } - it { is_expected.to have_many(:web_widgets).class_name('::Channel::WebWidget').dependent(:destroy) } - it { is_expected.to have_many(:webhooks).dependent(:destroy) } - it { is_expected.to have_many(:notification_settings).dependent(:destroy) } + it { is_expected.to have_many(:inboxes).dependent(:destroy_async) } + it { is_expected.to have_many(:conversations).dependent(:destroy_async) } + it { is_expected.to have_many(:contacts).dependent(:destroy_async) } + it { is_expected.to have_many(:telegram_bots).dependent(:destroy_async) } + it { is_expected.to have_many(:canned_responses).dependent(:destroy_async) } + it { is_expected.to have_many(:facebook_pages).class_name('::Channel::FacebookPage').dependent(:destroy_async) } + it { is_expected.to have_many(:web_widgets).class_name('::Channel::WebWidget').dependent(:destroy_async) } + it { is_expected.to have_many(:webhooks).dependent(:destroy_async) } + it { is_expected.to have_many(:notification_settings).dependent(:destroy_async) } it { is_expected.to have_many(:events) } - it { is_expected.to have_many(:kbase_portals).dependent(:destroy) } - it { is_expected.to have_many(:kbase_categories).dependent(:destroy) } - it { is_expected.to have_many(:teams).dependent(:destroy) } + it { is_expected.to have_many(:kbase_portals).dependent(:destroy_async) } + it { is_expected.to have_many(:kbase_categories).dependent(:destroy_async) } + it { is_expected.to have_many(:teams).dependent(:destroy_async) } end diff --git a/spec/models/channel/facebook_page_spec.rb b/spec/models/channel/facebook_page_spec.rb index 8d4b7abf6..02baac4a1 100644 --- a/spec/models/channel/facebook_page_spec.rb +++ b/spec/models/channel/facebook_page_spec.rb @@ -13,7 +13,7 @@ RSpec.describe Channel::FacebookPage do it { is_expected.to validate_presence_of(:account_id) } # it { is_expected.to validate_uniqueness_of(:page_id).scoped_to(:account_id) } it { is_expected.to belong_to(:account) } - it { is_expected.to have_one(:inbox).dependent(:destroy) } + it { is_expected.to have_one(:inbox).dependent(:destroy_async) } describe 'concerns' do it_behaves_like 'reauthorizable' diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index d296907cc..9833b392a 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -9,7 +9,7 @@ RSpec.describe Contact do context 'associations' do it { is_expected.to belong_to(:account) } - it { is_expected.to have_many(:conversations).dependent(:destroy) } + it { is_expected.to have_many(:conversations).dependent(:destroy_async) } end describe 'pubsub_token' do diff --git a/spec/models/inbox_spec.rb b/spec/models/inbox_spec.rb index 2150d7048..ba94540d8 100644 --- a/spec/models/inbox_spec.rb +++ b/spec/models/inbox_spec.rb @@ -13,21 +13,21 @@ RSpec.describe Inbox do it { is_expected.to belong_to(:channel) } - it { is_expected.to have_many(:contact_inboxes).dependent(:destroy) } + it { is_expected.to have_many(:contact_inboxes).dependent(:destroy_async) } it { is_expected.to have_many(:contacts).through(:contact_inboxes) } - it { is_expected.to have_many(:inbox_members).dependent(:destroy) } + it { is_expected.to have_many(:inbox_members).dependent(:destroy_async) } it { is_expected.to have_many(:members).through(:inbox_members).source(:user) } - it { is_expected.to have_many(:conversations).dependent(:destroy) } + it { is_expected.to have_many(:conversations).dependent(:destroy_async) } it { is_expected.to have_many(:messages).through(:conversations) } it { is_expected.to have_one(:agent_bot_inbox) } - it { is_expected.to have_many(:webhooks).dependent(:destroy) } + it { is_expected.to have_many(:webhooks).dependent(:destroy_async) } it { is_expected.to have_many(:events) } diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 5c4ce6850..674525a6f 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -16,8 +16,8 @@ RSpec.describe User do it { is_expected.to have_many(:accounts).through(:account_users) } it { is_expected.to have_many(:account_users) } it { is_expected.to have_many(:assigned_conversations).class_name('Conversation').dependent(:nullify) } - it { is_expected.to have_many(:inbox_members).dependent(:destroy) } - it { is_expected.to have_many(:notification_settings).dependent(:destroy) } + it { is_expected.to have_many(:inbox_members).dependent(:destroy_async) } + it { is_expected.to have_many(:notification_settings).dependent(:destroy_async) } it { is_expected.to have_many(:messages) } it { is_expected.to have_many(:events) } it { is_expected.to have_many(:teams) }