Skip to content

Commit 0e9c077

Browse files
committed
Wrap the disable referential integrity block in a transaction
If the block passed to disable referential integrity fails, triggers could be left disabled, so instead, make sure the disable, block contents, and enable are run in a transaction so they all run or nothing. Similar to https://www.github.com/rails/rails/pull/50196
1 parent a1054fa commit 0e9c077

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/extensions/database_cleaner-activerecord-seeded_deletion.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ module ActiveRecord
55
# SeededDeletion is a strategy that deletes all records from tables except those that existed before it was instantiated
66
# This is useful for tests that need the seeded data to be present.
77
class SeededDeletion < Deletion
8+
def clean
9+
connection.transaction(:requires_new => true) do
10+
super
11+
end
12+
end
13+
814
def start
915
Rails.logger.info "SeededDeletion strategy start"
1016
self.class.table_max_id_cache = table_max_id_hash

0 commit comments

Comments
 (0)