Class: DatabaseCleaner::Sequel::Truncation

Inherits:
Object
  • Object
show all
Includes:
Generic::Truncation, Base
Defined in:
lib/database_cleaner/sequel/truncation.rb

Direct Known Subclasses

Deletion

Instance Method Summary collapse

Methods included from Generic::Truncation

#initialize

Methods included from Base

#db, #db=

Methods included from Generic::Base

#cleaning, #db, included

Instance Method Details

#cleanObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/database_cleaner/sequel/truncation.rb', line 14

def clean
  return unless dirty?

  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 = tables_to_truncate(db)).empty?
      all_tables = tables.map { |t| %("#{t}") }.join(',')
      db.run "TRUNCATE TABLE #{all_tables};"
    end
  else
    tables = tables_to_truncate(db)

    if pre_count?
      # Count rows before truncating
      pre_count_truncate_tables(db, tables)
    else
      # Truncate each table normally
      truncate_tables(db, tables)
    end
  end
end

#startObject



10
11
12
# File 'lib/database_cleaner/sequel/truncation.rb', line 10

def start
  @last_txid = txid
end