mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
Merge pull request #166 from betelgeuse/faster_deletion_stragegy
One network trip for the deletion strategy
This commit is contained in:
commit
480fbebbbd
1 changed files with 5 additions and 48 deletions
|
@ -3,51 +3,6 @@ require 'active_record/connection_adapters/abstract_adapter'
|
||||||
require "database_cleaner/generic/truncation"
|
require "database_cleaner/generic/truncation"
|
||||||
require 'database_cleaner/active_record/base'
|
require 'database_cleaner/active_record/base'
|
||||||
require 'database_cleaner/active_record/truncation'
|
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 ActiveRecord
|
|
||||||
module ConnectionAdapters
|
|
||||||
|
|
||||||
class MysqlAdapter < MYSQL_ADAPTER_PARENT
|
|
||||||
def delete_table(table_name)
|
|
||||||
execute("DELETE FROM #{quote_table_name(table_name)};")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
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
|
module DatabaseCleaner::ActiveRecord
|
||||||
class Deletion < Truncation
|
class Deletion < Truncation
|
||||||
|
@ -55,9 +10,11 @@ module DatabaseCleaner::ActiveRecord
|
||||||
def clean
|
def clean
|
||||||
connection = connection_class.connection
|
connection = connection_class.connection
|
||||||
connection.disable_referential_integrity do
|
connection.disable_referential_integrity do
|
||||||
tables_to_truncate(connection).each do |table_name|
|
sql = tables_to_truncate(connection).map do |table_name|
|
||||||
connection.delete_table table_name
|
"DELETE FROM #{connection.quote_table_name(table_name)}"
|
||||||
end
|
end.join(";")
|
||||||
|
|
||||||
|
connection.execute sql
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue