提交 4b79db7d 编写于 作者: J John Crepezzi

Correctly establish connection in truncate and simplify method

We want to call establish connection, not `connected_to` with a database
key for truncate. Then we simplified the method by pushing the removed
tables into truncate.

This also removes an instance of unnecessarily calling
`configuration_hash` when we already have a `db_config` to pass around.
Co-authored-by: Neileencodes <eileencodes@gmail.com>
上级 41101f14
......@@ -188,6 +188,8 @@ def truncate(table_name, name = nil)
end
def truncate_tables(*table_names) # :nodoc:
table_names -= [schema_migration.table_name, InternalMetadata.table_name]
return if table_names.empty?
with_multi_statements do
......
......@@ -208,16 +208,10 @@ def drop_current(environment = env)
end
def truncate_tables(db_config)
ActiveRecord::Base.connected_to(database: { truncation: db_config.configuration_hash }) do
conn = ActiveRecord::Base.connection
table_names = conn.tables
table_names -= [
conn.schema_migration.table_name,
InternalMetadata.table_name
]
ActiveRecord::Base.connection.truncate_tables(*table_names)
end
ActiveRecord::Base.establish_connection(db_config)
connection = ActiveRecord::Base.connection
connection.truncate_tables(*connection.tables)
end
private :truncate_tables
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册