fix: drop conv and campaign seq on account delete (#4256)

Conversation and campaign sequences persist in the database even after the related account is deleted. This PR adds an after_desttory callback on the account model that will delete the associated sequences.

Fixes: #4252
This commit is contained in:
Vishnu Narayanan
2022-03-24 13:33:15 +05:30
committed by GitHub
parent 0cf970dafd
commit 7577c9c888
2 changed files with 16 additions and 0 deletions

View File

@@ -79,6 +79,7 @@ class Account < ApplicationRecord
before_validation :validate_limit_keys
after_create_commit :notify_creation
after_destroy :remove_account_sequences
def agents
users.where(account_users: { role: :agent })
@@ -137,4 +138,9 @@ class Account < ApplicationRecord
def validate_limit_keys
# method overridden in enterprise module
end
def remove_account_sequences
ActiveRecord::Base.connection.exec_query("drop sequence IF EXISTS camp_dpid_seq_#{id}")
ActiveRecord::Base.connection.exec_query("drop sequence IF EXISTS conv_dpid_seq_#{id}")
end
end