mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
Support different column names for MySQL and Postgres
This commit is contained in:
parent
db82bee534
commit
fdaa552f6e
3 changed files with 5 additions and 5 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 }
|
||||
|
|
Loading…
Reference in a new issue