Class: ActiveRecord::ConnectionAdapters::PostgreSQLAdapter

Inherits:
POSTGRE_ADAPTER_PARENT
  • Object
show all
Defined in:
lib/database_cleaner/active_record/deletion.rb,
lib/database_cleaner/active_record/truncation.rb

Instance Method Summary collapse

Instance Method Details

#cascadeObject



86
87
88
# File 'lib/database_cleaner/active_record/truncation.rb', line 86

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

#db_versionObject



82
83
84
# File 'lib/database_cleaner/active_record/truncation.rb', line 82

def db_version
  @db_version ||= postgresql_version
end

#delete_table(table_name) ⇒ Object



31
32
33
# File 'lib/database_cleaner/active_record/deletion.rb', line 31

def delete_table(table_name)
  execute("DELETE FROM #{quote_table_name(table_name)};")
end

#restart_identityObject



90
91
92
# File 'lib/database_cleaner/active_record/truncation.rb', line 90

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

#truncate_table(table_name) ⇒ Object



94
95
96
# File 'lib/database_cleaner/active_record/truncation.rb', line 94

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

#truncate_tables(table_names) ⇒ Object



98
99
100
101
# File 'lib/database_cleaner/active_record/truncation.rb', line 98

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