Revert "One network trip for the deletion strategy" See #192

This reverts commit 51527a0384.
This commit is contained in:
Ben Mabey 2013-08-01 09:53:15 -06:00
parent 5dc784af66
commit f75a9b01af

View file

@ -3,18 +3,61 @@ require 'active_record/connection_adapters/abstract_adapter'
require "database_cleaner/generic/truncation"
require 'database_cleaner/active_record/base'
require 'database_cleaner/active_record/truncation'
# This file may seem to have duplication with that of truncation, but by keeping them separate
# we avoiding loading this code when it is not being used (which is the common case).
module DatabaseCleaner::ActiveRecord
class Deletion < Truncation
module ActiveRecord
module ConnectionAdapters
def clean
connection = connection_class.connection
connection.disable_referential_integrity do
sql = tables_to_truncate(connection).map do |table_name|
"DELETE FROM #{connection.quote_table_name(table_name)}"
end.join(";")
class MysqlAdapter < MYSQL_ADAPTER_PARENT
def delete_table(table_name)
execute("DELETE FROM #{quote_table_name(table_name)};")
end
end
connection.execute sql
class Mysql2Adapter < MYSQL2_ADAPTER_PARENT
def delete_table(table_name)
execute("DELETE FROM #{quote_table_name(table_name)};")
end
end
class JdbcAdapter < AbstractAdapter
def delete_table(table_name)
execute("DELETE FROM #{quote_table_name(table_name)};")
end
end
class PostgreSQLAdapter < POSTGRE_ADAPTER_PARENT
def delete_table(table_name)
execute("DELETE FROM #{quote_table_name(table_name)};")
end
end
class SQLServerAdapter < AbstractAdapter
def delete_table(table_name)
execute("DELETE FROM #{quote_table_name(table_name)};")
end
end
class OracleEnhancedAdapter < AbstractAdapter
def delete_table(table_name)
execute("DELETE FROM #{quote_table_name(table_name)}")
end
end
end
end
module DatabaseCleaner::ActiveRecord
class Deletion < Truncation
def clean
connection = connection_class.connection
connection.disable_referential_integrity do
tables_to_truncate(connection).each do |table_name|
connection.delete_table table_name
end
end
end