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:
Mauro Otonelli 2017-05-31 20:09:41 +02:00 committed by GitHub
commit 9755bc55dc
4 changed files with 11 additions and 3 deletions

View file

@ -1,7 +1,7 @@
PATH PATH
remote: . remote: .
specs: specs:
database_cleaner (1.6.0) database_cleaner (1.6.1)
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/

View file

@ -65,6 +65,14 @@ module DatabaseCleaner
end end
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 private
def lookup_from_connection_pool def lookup_from_connection_pool

View file

@ -72,7 +72,7 @@ module DatabaseCleaner::ActiveRecord
INFORMATION_SCHEMA.TABLES INFORMATION_SCHEMA.TABLES
WHERE WHERE
table_schema = '#{db_name}' table_schema = '#{db_name}'
AND table_name <> '#{::DatabaseCleaner::ActiveRecord::Base.migration_table_name}'; AND #{::DatabaseCleaner::ActiveRecord::Base.exclusion_condition('table_name')};
SQL SQL
end end
end end

View file

@ -192,7 +192,7 @@ module DatabaseCleaner
FROM pg_tables FROM pg_tables
WHERE WHERE
tablename !~ '_prt_' AND tablename !~ '_prt_' AND
tablename <> '#{::DatabaseCleaner::ActiveRecord::Base.migration_table_name}' AND #{::DatabaseCleaner::ActiveRecord::Base.exclusion_condition('tablename')} AND
schemaname = ANY (current_schemas(false)) schemaname = ANY (current_schemas(false))
_SQL _SQL
rows.collect { |result| result.first } rows.collect { |result| result.first }