mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
Making the mysql deletion cleaner to touch only those tables that have new records in them
This commit is contained in:
parent
35bd646903
commit
8d0016e748
1 changed files with 14 additions and 0 deletions
|
@ -54,3 +54,17 @@ module DatabaseCleaner::ActiveRecord
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
if defined?(Mysql2Adapter)
|
||||
class DatabaseCleaner::ActiveRecord::Deletion
|
||||
def tables_to_truncate(connection)
|
||||
(@only || tables_with_new_rows(connection)) - @tables_to_exclude
|
||||
end
|
||||
|
||||
def tables_with_new_rows(connection)
|
||||
@db_name ||= connection.instance_variable_get('@config')[:database]
|
||||
result = connection.execute("SELECT table_name FROM information_schema.tables WHERE table_schema = '#{@db_name}' AND table_rows > 0")
|
||||
result.map{ |row| row[0] } - ['schema_migrations']
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue