mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
Merge pull request #487 from DatabaseCleaner/active-record-exclude-internal_metadata_table_name
Active record exclude internal metadata table name
This commit is contained in:
commit
9755bc55dc
4 changed files with 11 additions and 3 deletions
|
@ -1,7 +1,7 @@
|
|||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
database_cleaner (1.6.0)
|
||||
database_cleaner (1.6.1)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
|
|
|
@ -65,6 +65,14 @@ module DatabaseCleaner
|
|||
end
|
||||
end
|
||||
|
||||
def self.exclusion_condition(column_name)
|
||||
result = " #{column_name} <> '#{::DatabaseCleaner::ActiveRecord::Base.migration_table_name}' "
|
||||
if ::ActiveRecord::VERSION::MAJOR >= 5
|
||||
result += " AND #{column_name} <> '#{ActiveRecord::Base.internal_metadata_table_name}' "
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def lookup_from_connection_pool
|
||||
|
|
|
@ -72,7 +72,7 @@ module DatabaseCleaner::ActiveRecord
|
|||
INFORMATION_SCHEMA.TABLES
|
||||
WHERE
|
||||
table_schema = '#{db_name}'
|
||||
AND table_name <> '#{::DatabaseCleaner::ActiveRecord::Base.migration_table_name}';
|
||||
AND #{::DatabaseCleaner::ActiveRecord::Base.exclusion_condition('table_name')};
|
||||
SQL
|
||||
end
|
||||
end
|
||||
|
|
|
@ -192,7 +192,7 @@ module DatabaseCleaner
|
|||
FROM pg_tables
|
||||
WHERE
|
||||
tablename !~ '_prt_' AND
|
||||
tablename <> '#{::DatabaseCleaner::ActiveRecord::Base.migration_table_name}' AND
|
||||
#{::DatabaseCleaner::ActiveRecord::Base.exclusion_condition('tablename')} AND
|
||||
schemaname = ANY (current_schemas(false))
|
||||
_SQL
|
||||
rows.collect { |result| result.first }
|
||||
|
|
Loading…
Reference in a new issue