diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-03-06 09:41:17 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-03-06 09:44:01 +0900 |
commit | 2803c0382fe60423b5c17c1be37abaf1cc408819 (patch) | |
tree | d62b9ce9113a3202b0a23b0d80537257d74c40cd /activerecord/lib | |
parent | d731d6366ae68c790ef79ff66b2d2d41f5767cc3 (diff) | |
download | rails-2803c0382fe60423b5c17c1be37abaf1cc408819.tar.gz rails-2803c0382fe60423b5c17c1be37abaf1cc408819.tar.bz2 rails-2803c0382fe60423b5c17c1be37abaf1cc408819.zip |
Extract `SchemaMigration.all_versions`
Use `SchemaMigration.all_versions` instead of
`SchemaMigration.all.map(&:version)` to avoid to instantiate AR objects.
Diffstat (limited to 'activerecord/lib')
3 files changed, 8 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index cbb93e0ffe..a497a354f7 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -991,7 +991,7 @@ module ActiveRecord end def dump_schema_information #:nodoc: - versions = ActiveRecord::SchemaMigration.order("version").pluck(:version) + versions = ActiveRecord::SchemaMigration.all_versions insert_versions_sql(versions) end @@ -1027,7 +1027,7 @@ module ActiveRecord version = version.to_i sm_table = quote_table_name(ActiveRecord::SchemaMigration.table_name) - migrated = select_values("SELECT version FROM #{sm_table}").map(&:to_i) + migrated = ActiveRecord::SchemaMigration.all_versions.map(&:to_i) versions = ActiveRecord::Migrator.migration_files(migrations_paths).map do |file| ActiveRecord::Migrator.parse_migration_filename(file).first.to_i end diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index d8cf784933..3eb9171a5f 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -1024,7 +1024,7 @@ module ActiveRecord def get_all_versions(connection = Base.connection) if SchemaMigration.table_exists? - SchemaMigration.all.map { |x| x.version.to_i }.sort + SchemaMigration.all_versions.map(&:to_i) else [] end diff --git a/activerecord/lib/active_record/schema_migration.rb b/activerecord/lib/active_record/schema_migration.rb index 5efbcff96a..f59737afb0 100644 --- a/activerecord/lib/active_record/schema_migration.rb +++ b/activerecord/lib/active_record/schema_migration.rb @@ -39,7 +39,11 @@ module ActiveRecord end def normalized_versions - pluck(:version).map { |v| normalize_migration_number v } + all_versions.map { |v| normalize_migration_number v } + end + + def all_versions + order(:version).pluck(:version) end end |