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
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.exclusion_condition
|
def self.exclusion_condition(column_name)
|
||||||
result = " table_name <> '#{::DatabaseCleaner::ActiveRecord::Base.migration_table_name}' "
|
result = " #{column_name} <> '#{::DatabaseCleaner::ActiveRecord::Base.migration_table_name}' "
|
||||||
if ::ActiveRecord::VERSION::MAJOR >= 5
|
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
|
end
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
|
@ -72,7 +72,7 @@ module DatabaseCleaner::ActiveRecord
|
||||||
INFORMATION_SCHEMA.TABLES
|
INFORMATION_SCHEMA.TABLES
|
||||||
WHERE
|
WHERE
|
||||||
table_schema = '#{db_name}'
|
table_schema = '#{db_name}'
|
||||||
AND #{::DatabaseCleaner::ActiveRecord::Base.exclusion_condition};
|
AND #{::DatabaseCleaner::ActiveRecord::Base.exclusion_condition('table_name')};
|
||||||
SQL
|
SQL
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -192,7 +192,7 @@ module DatabaseCleaner
|
||||||
FROM pg_tables
|
FROM pg_tables
|
||||||
WHERE
|
WHERE
|
||||||
tablename !~ '_prt_' AND
|
tablename !~ '_prt_' AND
|
||||||
#{::DatabaseCleaner::ActiveRecord::Base.exclusion_condition} 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 }
|
||||||
|
|
Loading…
Reference in a new issue