class DatabaseCleaner::Sequel::Truncation

Public Instance Methods

clean() click to toggle source
# File lib/database_cleaner/sequel/truncation.rb, line 10
def clean
  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| %Q["#{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() { |db, to_sym| ... } click to toggle source
# File lib/database_cleaner/sequel/truncation.rb, line 29
def each_table
  tables_to_truncate(db).each do |table|
    yield db, table.to_sym
  end
end

Private Instance Methods

migration_storage_names() click to toggle source

overwritten

# File lib/database_cleaner/sequel/truncation.rb, line 42
def migration_storage_names
  %w[schema_info schema_migrations]
end
tables_to_truncate(db) click to toggle source
# File lib/database_cleaner/sequel/truncation.rb, line 37
def tables_to_truncate(db)
  (@only || db.tables.map(&:to_s)) - @tables_to_exclude
end