From 07788c7ad8bad797ec97cba038e37e007f343afa Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Mon, 4 Dec 2017 08:18:31 +0900 Subject: `current_version` should catch `NoDatabaseError` from `get_all_versions` `get_all_versions` doesn't use passed `connection`. So it should be caught `NoDatabaseError` from `SchemaMigration.table_exists?`. --- activerecord/lib/active_record/migration.rb | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index 4d4b0dc67a..5c10d4ff24 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -1045,7 +1045,7 @@ module ActiveRecord new(:up, migrations(migrations_paths), nil) end - def get_all_versions(connection = Base.connection) + def get_all_versions if SchemaMigration.table_exists? SchemaMigration.all_versions.map(&:to_i) else @@ -1054,19 +1054,12 @@ module ActiveRecord end def current_version(connection = nil) - if connection.nil? - begin - connection = Base.connection - rescue ActiveRecord::NoDatabaseError - return nil - end - end - - get_all_versions(connection).max || 0 + get_all_versions.max || 0 + rescue ActiveRecord::NoDatabaseError end - def needs_migration?(connection = Base.connection) - (migrations(migrations_paths).collect(&:version) - get_all_versions(connection)).size > 0 + def needs_migration?(connection = nil) + (migrations(migrations_paths).collect(&:version) - get_all_versions).size > 0 end def any_migrations? -- cgit v1.2.3