Class: DatabaseCleaner::Sequel::Truncation
- Inherits:
-
Object
- Object
- DatabaseCleaner::Sequel::Truncation
- Includes:
- Generic::Truncation, Base
- Defined in:
- lib/database_cleaner/sequel/truncation.rb
Direct Known Subclasses
Instance Method Summary collapse
Methods included from Base
Instance Method Details
#clean ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/database_cleaner/sequel/truncation.rb', line 14 def clean return unless dirty? tables = tables_to_truncate(db) # Count rows before truncating if pre_count? tables = pre_count_tables(tables) end case db.database_type 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.empty? tables_sql = tables.map { |t| %("#{t}") }.join(',') db.run "TRUNCATE TABLE #{tables_sql} RESTART IDENTITY;" end else truncate_tables(db, tables) end end |
#start ⇒ Object
10 11 12 |
# File 'lib/database_cleaner/sequel/truncation.rb', line 10 def start @last_txid = txid end |