Class: DatabaseCleaner::Sequel::Truncation
- Defined in:
- lib/database_cleaner/sequel/truncation.rb
Direct Known Subclasses
Instance Method Summary collapse
- #clean ⇒ Object
-
#initialize(opts = {}) ⇒ Truncation
constructor
A new instance of Truncation.
- #start ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(opts = {}) ⇒ Truncation
Returns a new instance of Truncation.
6 7 8 9 10 |
# File 'lib/database_cleaner/sequel/truncation.rb', line 6 def initialize(opts = {}) @only = opts[:only] || [] @except = opts[:except] || [] @pre_count = opts[:pre_count] || false end |
Instance Method Details
#clean ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/database_cleaner/sequel/truncation.rb', line 16 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
12 13 14 |
# File 'lib/database_cleaner/sequel/truncation.rb', line 12 def start @last_txid = txid end |