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:
@@ -30,4 +30,14 @@ RSpec.describe Account do
|
||||
expect(account.usage_limits).to eq({ agents: ChatwootApp.max_limit, inboxes: ChatwootApp.max_limit })
|
||||
end
|
||||
end
|
||||
|
||||
context 'when after_destroy is called' do
|
||||
it 'conv_dpid_seq and camp_dpid_seq_ are deleted' do
|
||||
account = create(:account)
|
||||
query = "select * from information_schema.sequences where sequence_name in ('camp_dpid_seq_#{account.id}', 'conv_dpid_seq_#{account.id}');"
|
||||
expect(ActiveRecord::Base.connection.execute(query).count).to eq(2)
|
||||
account.destroy
|
||||
expect(ActiveRecord::Base.connection.execute(query).count).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user