Chore: Replaced dependent destroy with dependent destroy_async in all models (#3249)

This commit is contained in:
Akhil G Krishnan 2021-11-18 10:32:29 +05:30 committed by GitHub
parent 4eeaadbd5b
commit b81a9f2010
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 90 additions and 90 deletions

View file

@ -32,40 +32,40 @@ class Account < ApplicationRecord
validates :name, presence: true validates :name, presence: true
validates :auto_resolve_duration, numericality: { greater_than_or_equal_to: 1, allow_nil: true } validates :auto_resolve_duration, numericality: { greater_than_or_equal_to: 1, allow_nil: true }
has_many :account_users, dependent: :destroy has_many :account_users, dependent: :destroy_async
has_many :agent_bot_inboxes, dependent: :destroy has_many :agent_bot_inboxes, dependent: :destroy_async
has_many :agent_bots, dependent: :destroy has_many :agent_bots, dependent: :destroy_async
has_many :csat_survey_responses, dependent: :destroy has_many :csat_survey_responses, dependent: :destroy_async
has_many :data_imports, dependent: :destroy has_many :data_imports, dependent: :destroy_async
has_many :users, through: :account_users has_many :users, through: :account_users
has_many :inboxes, dependent: :destroy has_many :inboxes, dependent: :destroy_async
has_many :notes, dependent: :destroy has_many :notes, dependent: :destroy_async
has_many :campaigns, dependent: :destroy has_many :campaigns, dependent: :destroy_async
has_many :conversations, dependent: :destroy has_many :conversations, dependent: :destroy_async
has_many :messages, dependent: :destroy has_many :messages, dependent: :destroy_async
has_many :contacts, dependent: :destroy has_many :contacts, dependent: :destroy_async
has_many :facebook_pages, dependent: :destroy, class_name: '::Channel::FacebookPage' has_many :facebook_pages, dependent: :destroy_async, class_name: '::Channel::FacebookPage'
has_many :telegram_bots, dependent: :destroy has_many :telegram_bots, dependent: :destroy_async
has_many :twilio_sms, dependent: :destroy, class_name: '::Channel::TwilioSms' has_many :twilio_sms, dependent: :destroy_async, class_name: '::Channel::TwilioSms'
has_many :twitter_profiles, dependent: :destroy, class_name: '::Channel::TwitterProfile' has_many :twitter_profiles, dependent: :destroy_async, class_name: '::Channel::TwitterProfile'
has_many :web_widgets, dependent: :destroy, class_name: '::Channel::WebWidget' has_many :web_widgets, dependent: :destroy_async, class_name: '::Channel::WebWidget'
has_many :email_channels, dependent: :destroy, class_name: '::Channel::Email' has_many :email_channels, dependent: :destroy_async, class_name: '::Channel::Email'
has_many :api_channels, dependent: :destroy, class_name: '::Channel::Api' has_many :api_channels, dependent: :destroy_async, class_name: '::Channel::Api'
has_many :line_channels, dependent: :destroy, class_name: '::Channel::Line' has_many :line_channels, dependent: :destroy_async, class_name: '::Channel::Line'
has_many :telegram_channels, dependent: :destroy, class_name: '::Channel::Telegram' has_many :telegram_channels, dependent: :destroy_async, class_name: '::Channel::Telegram'
has_many :whatsapp_channels, dependent: :destroy, class_name: '::Channel::Whatsapp' has_many :whatsapp_channels, dependent: :destroy_async, class_name: '::Channel::Whatsapp'
has_many :canned_responses, dependent: :destroy has_many :canned_responses, dependent: :destroy_async
has_many :webhooks, dependent: :destroy has_many :webhooks, dependent: :destroy_async
has_many :labels, dependent: :destroy has_many :labels, dependent: :destroy_async
has_many :notification_settings, dependent: :destroy has_many :notification_settings, dependent: :destroy_async
has_many :hooks, dependent: :destroy, class_name: 'Integrations::Hook' has_many :hooks, dependent: :destroy_async, class_name: 'Integrations::Hook'
has_many :working_hours, dependent: :destroy has_many :working_hours, dependent: :destroy_async
has_many :kbase_portals, dependent: :destroy, class_name: '::Kbase::Portal' has_many :kbase_portals, dependent: :destroy_async, class_name: '::Kbase::Portal'
has_many :kbase_categories, dependent: :destroy, class_name: '::Kbase::Category' has_many :kbase_categories, dependent: :destroy_async, class_name: '::Kbase::Category'
has_many :kbase_articles, dependent: :destroy, class_name: '::Kbase::Article' has_many :kbase_articles, dependent: :destroy_async, class_name: '::Kbase::Article'
has_many :teams, dependent: :destroy has_many :teams, dependent: :destroy_async
has_many :custom_filters, dependent: :destroy has_many :custom_filters, dependent: :destroy_async
has_many :custom_attribute_definitions, dependent: :destroy has_many :custom_attribute_definitions, dependent: :destroy_async
has_flags ACCOUNT_SETTINGS_FLAGS.merge(column: 'settings_flags').merge(DEFAULT_QUERY_SETTING) has_flags ACCOUNT_SETTINGS_FLAGS.merge(column: 'settings_flags').merge(DEFAULT_QUERY_SETTING)

View file

@ -23,10 +23,10 @@ class AgentBot < ApplicationRecord
include AccessTokenable include AccessTokenable
include Avatarable 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 :inboxes, through: :agent_bot_inboxes
has_many :messages, as: :sender, dependent: :restrict_with_exception 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 def available_name
name name

View file

@ -1,7 +1,7 @@
module AccessTokenable module AccessTokenable
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do
has_one :access_token, as: :owner, dependent: :destroy has_one :access_token, as: :owner, dependent: :destroy_async
after_create :create_access_token after_create :create_access_token
end end

View file

@ -3,7 +3,7 @@ module Channelable
included do included do
validates :account_id, presence: true validates :account_id, presence: true
belongs_to :account belongs_to :account
has_one :inbox, as: :channel, dependent: :destroy has_one :inbox, as: :channel, dependent: :destroy_async
end end
def has_24_hour_messaging_window? def has_24_hour_messaging_window?

View file

@ -6,7 +6,7 @@ module OutOfOffisable
OFFISABLE_ATTRS = %w[day_of_week closed_all_day open_hour open_minutes close_hour close_minutes].freeze OFFISABLE_ATTRS = %w[day_of_week closed_all_day open_hour open_minutes close_hour close_minutes].freeze
included do included do
has_many :working_hours, dependent: :destroy has_many :working_hours, dependent: :destroy_async
after_create :create_default_working_hours after_create :create_default_working_hours
end end

View file

@ -4,6 +4,6 @@ module Reportable
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do
has_many :events, dependent: :destroy has_many :events, dependent: :destroy_async
end end
end end

View file

@ -38,12 +38,12 @@ class Contact < ApplicationRecord
format: { with: /\+[1-9]\d{1,14}\z/, message: 'should be in e164 format' } format: { with: /\+[1-9]\d{1,14}\z/, message: 'should be in e164 format' }
belongs_to :account belongs_to :account
has_many :conversations, dependent: :destroy has_many :conversations, dependent: :destroy_async
has_many :contact_inboxes, dependent: :destroy has_many :contact_inboxes, dependent: :destroy_async
has_many :csat_survey_responses, dependent: :destroy has_many :csat_survey_responses, dependent: :destroy_async
has_many :inboxes, through: :contact_inboxes has_many :inboxes, through: :contact_inboxes
has_many :messages, as: :sender, dependent: :destroy has_many :messages, as: :sender, dependent: :destroy_async
has_many :notes, dependent: :destroy has_many :notes, dependent: :destroy_async
before_validation :prepare_email_attribute before_validation :prepare_email_attribute
after_create_commit :dispatch_create_event, :ip_lookup after_create_commit :dispatch_create_event, :ip_lookup

View file

@ -32,7 +32,7 @@ class ContactInbox < ApplicationRecord
belongs_to :contact belongs_to :contact
belongs_to :inbox belongs_to :inbox
has_many :conversations, dependent: :destroy has_many :conversations, dependent: :destroy_async
def webhook_data def webhook_data
{ {

View file

@ -66,8 +66,8 @@ class Conversation < ApplicationRecord
belongs_to :team, optional: true belongs_to :team, optional: true
belongs_to :campaign, optional: true belongs_to :campaign, optional: true
has_many :messages, dependent: :destroy, autosave: true has_many :messages, dependent: :destroy_async, autosave: true
has_one :csat_survey_response, dependent: :destroy has_one :csat_survey_response, dependent: :destroy_async
has_many :notifications, as: :primary_actor, dependent: :destroy has_many :notifications, as: :primary_actor, dependent: :destroy
before_save :ensure_snooze_until_reset before_save :ensure_snooze_until_reset

View file

@ -39,19 +39,19 @@ class Inbox < ApplicationRecord
belongs_to :channel, polymorphic: true, dependent: :destroy belongs_to :channel, polymorphic: true, dependent: :destroy
has_many :campaigns, dependent: :destroy has_many :campaigns, dependent: :destroy_async
has_many :contact_inboxes, dependent: :destroy has_many :contact_inboxes, dependent: :destroy_async
has_many :contacts, through: :contact_inboxes 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 :members, through: :inbox_members, source: :user
has_many :conversations, dependent: :destroy has_many :conversations, dependent: :destroy_async
has_many :messages, through: :conversations 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_one :agent_bot, through: :agent_bot_inbox
has_many :webhooks, dependent: :destroy has_many :webhooks, dependent: :destroy_async
has_many :hooks, dependent: :destroy, class_name: 'Integrations::Hook' has_many :hooks, dependent: :destroy_async, class_name: 'Integrations::Hook'
after_destroy :delete_round_robin_agents after_destroy :delete_round_robin_agents

View file

@ -14,7 +14,7 @@
class Kbase::Category < ApplicationRecord class Kbase::Category < ApplicationRecord
belongs_to :account belongs_to :account
belongs_to :portal belongs_to :portal
has_many :folders, dependent: :destroy has_many :folders, dependent: :destroy_async
has_many :articles, dependent: :nullify has_many :articles, dependent: :nullify
before_validation :ensure_account_id before_validation :ensure_account_id

View file

@ -20,9 +20,9 @@
# #
class Kbase::Portal < ApplicationRecord class Kbase::Portal < ApplicationRecord
belongs_to :account belongs_to :account
has_many :categories, dependent: :destroy has_many :categories, dependent: :destroy_async
has_many :folders, through: :categories has_many :folders, through: :categories
has_many :articles, dependent: :destroy has_many :articles, dependent: :destroy_async
validates :account_id, presence: true validates :account_id, presence: true
validates :name, presence: true validates :name, presence: true

View file

@ -82,8 +82,8 @@ class Message < ApplicationRecord
belongs_to :contact, required: false belongs_to :contact, required: false
belongs_to :sender, polymorphic: true, required: false belongs_to :sender, polymorphic: true, required: false
has_many :attachments, dependent: :destroy, autosave: true, before_add: :validate_attachments_limit has_many :attachments, dependent: :destroy_async, autosave: true, before_add: :validate_attachments_limit
has_one :csat_survey_response, dependent: :destroy has_one :csat_survey_response, dependent: :destroy_async
after_create_commit :execute_after_create_commit_callbacks after_create_commit :execute_after_create_commit_callbacks

View file

@ -12,5 +12,5 @@ class PlatformApp < ApplicationRecord
validates :name, presence: true validates :name, presence: true
has_many :platform_app_permissibles, dependent: :destroy has_many :platform_app_permissibles, dependent: :destroy_async
end end

View file

@ -22,5 +22,5 @@ class PlatformAppPermissible < ApplicationRecord
validates :platform_app_id, uniqueness: { scope: [:permissible_id, :permissible_type] } validates :platform_app_id, uniqueness: { scope: [:permissible_id, :permissible_type] }
belongs_to :platform_app belongs_to :platform_app
belongs_to :permissible, polymorphic: true, dependent: :destroy belongs_to :permissible, polymorphic: true, dependent: :destroy_async
end end

View file

@ -21,7 +21,7 @@
# #
class Team < ApplicationRecord class Team < ApplicationRecord
belongs_to :account 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 :members, through: :team_members, source: :user
has_many :conversations, dependent: :nullify has_many :conversations, dependent: :nullify

View file

@ -12,6 +12,6 @@
class TelegramBot < ApplicationRecord class TelegramBot < ApplicationRecord
belongs_to :account 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 validates_uniqueness_of :auth_key, scope: :account_id
end end

View file

@ -67,7 +67,7 @@ class User < ApplicationRecord
validates :email, :name, presence: true validates :email, :name, presence: true
validates_length_of :name, minimum: 1 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 has_many :accounts, through: :account_users
accepts_nested_attributes_for :account_users accepts_nested_attributes_for :account_users
@ -75,18 +75,18 @@ class User < ApplicationRecord
alias_attribute :conversations, :assigned_conversations alias_attribute :conversations, :assigned_conversations
has_many :csat_survey_responses, foreign_key: 'assigned_agent_id', dependent: :nullify 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 :inboxes, through: :inbox_members, source: :inbox
has_many :messages, as: :sender has_many :messages, as: :sender
has_many :invitees, through: :account_users, class_name: 'User', foreign_key: 'inviter_id', source: :inviter, dependent: :nullify has_many :invitees, through: :account_users, class_name: 'User', foreign_key: 'inviter_id', source: :inviter, dependent: :nullify
has_many :notifications, dependent: :destroy has_many :notifications, dependent: :destroy_async
has_many :notification_settings, dependent: :destroy has_many :notification_settings, dependent: :destroy_async
has_many :notification_subscriptions, dependent: :destroy has_many :notification_subscriptions, dependent: :destroy_async
has_many :team_members, dependent: :destroy has_many :team_members, dependent: :destroy_async
has_many :teams, through: :team_members has_many :teams, through: :team_members
has_many :notes, dependent: :nullify 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 before_validation :set_password_and_uid, on: :create

View file

@ -8,17 +8,17 @@ RSpec.describe Account do
it { is_expected.to have_many(:users).through(:account_users) } it { is_expected.to have_many(:users).through(:account_users) }
it { is_expected.to have_many(: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(:inboxes).dependent(:destroy_async) }
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(:contacts).dependent(:destroy) } it { is_expected.to have_many(:contacts).dependent(:destroy_async) }
it { is_expected.to have_many(:telegram_bots).dependent(:destroy) } it { is_expected.to have_many(:telegram_bots).dependent(:destroy_async) }
it { is_expected.to have_many(:canned_responses).dependent(:destroy) } 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) } 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) } it { is_expected.to have_many(:web_widgets).class_name('::Channel::WebWidget').dependent(:destroy_async) }
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(:notification_settings).dependent(:destroy) } it { is_expected.to have_many(:notification_settings).dependent(:destroy_async) }
it { is_expected.to have_many(:events) } it { is_expected.to have_many(:events) }
it { is_expected.to have_many(:kbase_portals).dependent(:destroy) } it { is_expected.to have_many(:kbase_portals).dependent(:destroy_async) }
it { is_expected.to have_many(:kbase_categories).dependent(:destroy) } it { is_expected.to have_many(:kbase_categories).dependent(:destroy_async) }
it { is_expected.to have_many(:teams).dependent(:destroy) } it { is_expected.to have_many(:teams).dependent(:destroy_async) }
end end

View file

@ -13,7 +13,7 @@ RSpec.describe Channel::FacebookPage do
it { is_expected.to validate_presence_of(:account_id) } 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 validate_uniqueness_of(:page_id).scoped_to(:account_id) }
it { is_expected.to belong_to(:account) } 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 describe 'concerns' do
it_behaves_like 'reauthorizable' it_behaves_like 'reauthorizable'

View file

@ -9,7 +9,7 @@ RSpec.describe Contact do
context 'associations' do context 'associations' do
it { is_expected.to belong_to(:account) } 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 end
describe 'pubsub_token' do describe 'pubsub_token' do

View file

@ -13,21 +13,21 @@ RSpec.describe Inbox do
it { is_expected.to belong_to(:channel) } 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(: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(: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_many(:messages).through(:conversations) }
it { is_expected.to have_one(:agent_bot_inbox) } 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) } it { is_expected.to have_many(:events) }

View file

@ -16,8 +16,8 @@ RSpec.describe User do
it { is_expected.to have_many(:accounts).through(:account_users) } it { is_expected.to have_many(:accounts).through(:account_users) }
it { is_expected.to have_many(: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(:assigned_conversations).class_name('Conversation').dependent(:nullify) }
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(:notification_settings).dependent(:destroy) } it { is_expected.to have_many(:notification_settings).dependent(:destroy_async) }
it { is_expected.to have_many(:messages) } it { is_expected.to have_many(:messages) }
it { is_expected.to have_many(:events) } it { is_expected.to have_many(:events) }
it { is_expected.to have_many(:teams) } it { is_expected.to have_many(:teams) }