Module: DatabaseCleaner::ConnectionAdapters::PostgreSQLAdapter

Defined in:
lib/database_cleaner/active_record/truncation.rb

Instance Method Summary collapse

Instance Method Details

#cascadeObject



134
135
136
# File 'lib/database_cleaner/active_record/truncation.rb', line 134

def cascade
  @cascade ||= db_version >=  80200 ? 'CASCADE' : ''
end

#db_versionObject



130
131
132
# File 'lib/database_cleaner/active_record/truncation.rb', line 130

def db_version
  @db_version ||= postgresql_version
end

#pre_count_truncate_tables(tables, options = {:reset_ids => true}) ⇒ Object



151
152
153
154
# File 'lib/database_cleaner/active_record/truncation.rb', line 151

def pre_count_truncate_tables(tables, options = {:reset_ids => true})
  filter = options[:reset_ids] ? method(:has_been_used?) : method(:has_rows?)
  truncate_tables(tables.select(&filter))
end

#restart_identityObject



138
139
140
# File 'lib/database_cleaner/active_record/truncation.rb', line 138

def restart_identity
  @restart_identity ||= db_version >=  80400 ? 'RESTART IDENTITY' : ''
end

#truncate_table(table_name) ⇒ Object



142
143
144
# File 'lib/database_cleaner/active_record/truncation.rb', line 142

def truncate_table(table_name)
  truncate_tables([table_name])
end

#truncate_tables(table_names) ⇒ Object



146
147
148
149
# File 'lib/database_cleaner/active_record/truncation.rb', line 146

def truncate_tables(table_names)
  return if table_names.nil? || table_names.empty?
  execute("TRUNCATE TABLE #{table_names.map{|name| quote_table_name(name)}.join(', ')} #{restart_identity} #{cascade};")
end