Class: ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
- Inherits:
-
POSTGRE_ADAPTER_PARENT
- Object
- ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
- Defined in:
- lib/database_cleaner/active_record/deletion.rb,
lib/database_cleaner/active_record/truncation.rb
Instance Method Summary collapse
- #cascade ⇒ Object
- #db_version ⇒ Object
- #delete_table(table_name) ⇒ Object
- #restart_identity ⇒ Object
- #truncate_table(table_name) ⇒ Object
- #truncate_tables(table_names) ⇒ Object
Instance Method Details
#cascade ⇒ Object
86 87 88 |
# File 'lib/database_cleaner/active_record/truncation.rb', line 86 def cascade @cascade ||= db_version >= 80200 ? 'CASCADE' : '' end |
#db_version ⇒ Object
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_identity ⇒ Object
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 |