Sha256: d858f63239ae8f3a4537d1f6b74bc5e1cc5da3a8a3c9f767598ef865587634e1
Contents?: true
Size: 1.29 KB
Versions: 2
Compression:
Stored size: 1.29 KB
Contents
require "database_cleaner/generic/truncation" require 'database_cleaner/sequel/base' module DatabaseCleaner module Sequel class Truncation include ::DatabaseCleaner::Sequel::Base include ::DatabaseCleaner::Generic::Truncation 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| %["#{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 def each_table tables_to_truncate(db).each do |table| yield db, table end end private def tables_to_truncate(db) (@only || db.tables.map(&:to_s)) - @tables_to_exclude end # overwritten def migration_storage_names %w[schema_info schema_migrations] end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
database_cleaner-1.0.1 | lib/database_cleaner/sequel/truncation.rb |
database_cleaner-1.0.0.RC1 | lib/database_cleaner/sequel/truncation.rb |