Class: DatabaseCleaner::Sequel::Truncation
- Inherits:
-
Object
- Object
- DatabaseCleaner::Sequel::Truncation
- Includes:
- Generic::Truncation, Base
- Defined in:
- lib/database_cleaner/sequel/truncation.rb
Instance Method Summary collapse
Methods included from Generic::Truncation
Methods included from Base
Methods included from Generic::Base
Instance Method Details
#clean ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/database_cleaner/sequel/truncation.rb', line 10 def clean case db_type= db.url.sub(/:.+/,'').to_sym when :postgres # PostgreSQL requires all tables with FKs to be truncates in the same command, or have the CASCADE keyword # appended. Bulk truncation without CASCADE is: # * Safer. Tables outside of tables_to_truncate won't be affected. # * Faster. Less roundtrips to the db. unless (tables= tables_to_truncate(db)).empty? all_tables= tables.map{|t| %["#{t}"]}.join ',' db.run "TRUNCATE TABLE #{all_tables};" end else # Truncate each table normally each_table do |db, table| db[table].truncate end end end |
#each_table ⇒ Object
29 30 31 32 33 |
# File 'lib/database_cleaner/sequel/truncation.rb', line 29 def each_table tables_to_truncate(db).each do |table| yield db, table end end |