Support different column names for MySQL and Postgres

This commit is contained in:
Ernesto Tagwerker 2017-05-17 14:38:46 -04:00
parent db82bee534
commit fdaa552f6e
3 changed files with 5 additions and 5 deletions

View file

@ -65,10 +65,10 @@ module DatabaseCleaner
end
end
def self.exclusion_condition
result = " table_name <> '#{::DatabaseCleaner::ActiveRecord::Base.migration_table_name}' "
def self.exclusion_condition(column_name)
result = " #{column_name} <> '#{::DatabaseCleaner::ActiveRecord::Base.migration_table_name}' "
if ::ActiveRecord::VERSION::MAJOR >= 5
result += " AND table_name <> '#{ActiveRecord::Base.internal_metadata_table_name}' "
result += " AND #{column_name} <> '#{ActiveRecord::Base.internal_metadata_table_name}' "
end
result
end

View file

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

View file

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