From 1f40782952bf41dfed222e71c02999eafbd7bfa9 Mon Sep 17 00:00:00 2001 From: Ernesto Tagwerker Date: Tue, 2 May 2017 15:37:43 -0400 Subject: [PATCH] Move migration_table_name to ActiveRecord::Base --- lib/database_cleaner/active_record/base.rb | 8 ++++++++ lib/database_cleaner/active_record/deletion.rb | 2 +- lib/database_cleaner/active_record/truncation.rb | 12 ++---------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/database_cleaner/active_record/base.rb b/lib/database_cleaner/active_record/base.rb index 85bf50b..1540483 100644 --- a/lib/database_cleaner/active_record/base.rb +++ b/lib/database_cleaner/active_record/base.rb @@ -57,6 +57,14 @@ module DatabaseCleaner end end + def self.migration_table_name + if ::ActiveRecord::VERSION::MAJOR < 5 + ::ActiveRecord::Migrator.schema_migrations_table_name + else + ::ActiveRecord::SchemaMigration.table_name + end + end + private def lookup_from_connection_pool diff --git a/lib/database_cleaner/active_record/deletion.rb b/lib/database_cleaner/active_record/deletion.rb index 90a7900..6867d2c 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 table_name <> 'schema_migrations'; + AND table_name <> '#{migration_table_name}'; SQL end end diff --git a/lib/database_cleaner/active_record/truncation.rb b/lib/database_cleaner/active_record/truncation.rb index 6e043d1..d3f91c6 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 - tablename <> '#{migration_table_name}' AND + tablename <> '#{::DatabaseCleaner::ActiveRecord::Base.migration_table_name}' AND schemaname = ANY (current_schemas(false)) _SQL rows.collect { |result| result.first } @@ -257,15 +257,7 @@ module DatabaseCleaner::ActiveRecord # overwritten def migration_storage_names - [migration_table_name] - end - - def migration_table_name - if ActiveRecord::VERSION::MAJOR < 5 - ::ActiveRecord::Migrator.schema_migrations_table_name - else - ::ActiveRecord::SchemaMigration.table_name - end + [::DatabaseCleaner::ActiveRecord::Base.migration_table_name] end def cache_tables?