From fdaa552f6edfbc7f7a68f6440a4d0fcc97c9f8fd Mon Sep 17 00:00:00 2001 From: Ernesto Tagwerker Date: Wed, 17 May 2017 14:38:46 -0400 Subject: [PATCH] Support different column names for MySQL and Postgres --- lib/database_cleaner/active_record/base.rb | 6 +++--- lib/database_cleaner/active_record/deletion.rb | 2 +- lib/database_cleaner/active_record/truncation.rb | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/database_cleaner/active_record/base.rb b/lib/database_cleaner/active_record/base.rb index 5f2d885..42a0b51 100644 --- a/lib/database_cleaner/active_record/base.rb +++ b/lib/database_cleaner/active_record/base.rb @@ -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 diff --git a/lib/database_cleaner/active_record/deletion.rb b/lib/database_cleaner/active_record/deletion.rb index dc99cd7..59a41c4 100644 --- a/lib/database_cleaner/active_record/deletion.rb +++ b/lib/database_cleaner/active_record/deletion.rb @@ -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 diff --git a/lib/database_cleaner/active_record/truncation.rb b/lib/database_cleaner/active_record/truncation.rb index 39c7f75..a470a6c 100644 --- a/lib/database_cleaner/active_record/truncation.rb +++ b/lib/database_cleaner/active_record/truncation.rb @@ -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 }