aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2019-03-10 01:53:48 +0900
committerRyuta Kamizono <kamipo@gmail.com>2019-03-17 05:20:46 +0900
commitfdac932707fb16b7d074b1d0bc7c255157d72675 (patch)
tree7932190a3b429886c69e3209926ce766ebce0895 /activerecord/lib/active_record/connection_adapters/postgresql
parent1db05065434e1b5341e6748632e310060e92b80d (diff)
downloadrails-fdac932707fb16b7d074b1d0bc7c255157d72675.tar.gz
rails-fdac932707fb16b7d074b1d0bc7c255157d72675.tar.bz2
rails-fdac932707fb16b7d074b1d0bc7c255157d72675.zip
Extract `truncate` and `truncate_tables` into database statements
This is to easier make `truncate_tables` to bulk statements.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb
index 41633872e2..208934385f 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb
@@ -143,6 +143,12 @@ module ActiveRecord
end
end
+ def truncate_tables(*table_names) # :nodoc:
+ unless table_names.empty?
+ execute "TRUNCATE TABLE #{table_names.map(&method(:quote_table_name)).join(", ")}"
+ end
+ end
+
# Begins a transaction.
def begin_db_transaction
execute "BEGIN"