提交 b707a448 编写于 作者: R Ryuta Kamizono

Tweak `truncate_tables`

* Remove redundant `table_names.empty?`
* Early return in `truncate_tables` since it is already deeply nested
* Move `truncate_tables` out from between `exec_delete` and `exec_update`
上级 d8d6bd5e
......@@ -142,23 +142,6 @@ def exec_delete(sql, name = nil, binds = [])
exec_query(sql, name, binds)
end
# Executes the truncate statement.
def truncate(table_name, name = nil)
execute(build_truncate_statements(table_name), name)
end
def truncate_tables(*table_names) # :nodoc:
unless table_names.empty?
with_multi_statements do
disable_referential_integrity do
Array(build_truncate_statements(*table_names)).each do |sql|
execute_batch(sql, "Truncate Tables")
end
end
end
end
end
# Executes update +sql+ statement in the context of this connection using
# +binds+ as the bind substitutes. +name+ is logged along with
# the executed +sql+ statement.
......@@ -193,6 +176,23 @@ def delete(arel, name = nil, binds = [])
exec_delete(sql, name, binds)
end
# Executes the truncate statement.
def truncate(table_name, name = nil)
execute(build_truncate_statements(table_name), name)
end
def truncate_tables(*table_names) # :nodoc:
return if table_names.empty?
with_multi_statements do
disable_referential_integrity do
Array(build_truncate_statements(*table_names)).each do |sql|
execute_batch(sql, "Truncate Tables")
end
end
end
end
# Runs the given block in a database transaction, and returns the result
# of the block.
#
......
......@@ -190,7 +190,7 @@ def truncate_tables(configuration)
ActiveRecord::Base.internal_metadata_table_name
]
ActiveRecord::Base.connection.truncate_tables(*table_names) unless table_names.empty?
ActiveRecord::Base.connection.truncate_tables(*table_names)
end
end
private :truncate_tables
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册