Class: DatabaseCleaner::Sequel::Truncation

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

Instance Method Summary collapse

Methods included from Generic::Truncation

#initialize, #start

Methods included from Base

#db, #db=

Methods included from Generic::Base

#db, included

Instance Method Details

#cleanObject



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_tableObject



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