diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-12-04 08:18:31 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-12-04 08:31:51 +0900 |
commit | 07788c7ad8bad797ec97cba038e37e007f343afa (patch) | |
tree | 35851e167bce2d4e10ed60145ef4bb12bfcf877f | |
parent | 14a1ad2f5abbb6dc6494ac531dba99d38a178858 (diff) | |
download | rails-07788c7ad8bad797ec97cba038e37e007f343afa.tar.gz rails-07788c7ad8bad797ec97cba038e37e007f343afa.tar.bz2 rails-07788c7ad8bad797ec97cba038e37e007f343afa.zip |
`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?`.
-rw-r--r-- | activerecord/lib/active_record/migration.rb | 17 |
1 files 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? |