Method: Webhookdb::SpecHelpers::Postgres.truncate_all
- Defined in:
- lib/webhookdb/spec_helpers/postgres.rb
.truncate_all ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/webhookdb/spec_helpers/postgres.rb', line 118 module_function def truncate_all # We can delete items from 'leaf' to 'trunk' in association terms # by using the TSort API (so Address and Customer, for example, are very early, # while 'StripeAttributes', which nothing has an FK into, is very late). # This is much faster than truncating with cascade. # Though in some cases, it doesn't work, so we need to cascade. Webhookdb::Postgres.each_model_superclass do |sc| sc.tsort.reverse_each do |m| m.dataset.delete rescue Sequel::ForeignKeyConstraintViolation m.truncate(cascade: true) rescue Sequel::DatabaseError # The table may not exist, maybe because the type was created in a test # and now no longer exists but it still a subclass. nil end end end |