aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-12-28 10:03:04 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-12-28 10:17:12 +0900
commit22a6ff68b1264de693364dd89be651dda9626284 (patch)
tree3b286817edd5b44e942da6b848445500481090a1 /activerecord/lib/active_record
parentc1b14aded27e063ead32fa911aa53163d7cfc21a (diff)
downloadrails-22a6ff68b1264de693364dd89be651dda9626284.tar.gz
rails-22a6ff68b1264de693364dd89be651dda9626284.tar.bz2
rails-22a6ff68b1264de693364dd89be651dda9626284.zip
Use high level API on `migration_context` instead of using low level API directly
Since `migration_context` has `migrations_paths` itself and provides methods which returning values from parsed migration files, so there is no reason to use the `parse_migration_filename` low level API directly.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb6
-rw-r--r--activerecord/lib/active_record/migration.rb18
2 files changed, 11 insertions, 13 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 f9ec343156..208c8c9c64 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -1061,10 +1061,8 @@ module ActiveRecord
version = version.to_i
sm_table = quote_table_name(ActiveRecord::SchemaMigration.table_name)
- migrated = ActiveRecord::SchemaMigration.all_versions.map(&:to_i)
- versions = migration_context.migration_files.map do |file|
- migration_context.parse_migration_filename(file).first.to_i
- end
+ migrated = migration_context.get_all_versions
+ versions = migration_context.migrations.map(&:version)
unless migrated.include?(version)
execute "INSERT INTO #{sm_table} (version) VALUES (#{quote(version)})"
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb
index 24782f8748..eca64eb380 100644
--- a/activerecord/lib/active_record/migration.rb
+++ b/activerecord/lib/active_record/migration.rb
@@ -1087,10 +1087,6 @@ module ActiveRecord
migrations.last || NullMigration.new
end
- def parse_migration_filename(filename) # :nodoc:
- File.basename(filename).scan(Migration::MigrationFilenameRegexp).first
- end
-
def migrations
migrations = migration_files.map do |file|
version, name, scope = parse_migration_filename(file)
@@ -1122,11 +1118,6 @@ module ActiveRecord
(db_list + file_list).sort_by { |_, version, _| version }
end
- def migration_files
- paths = Array(migrations_paths)
- Dir[*paths.flat_map { |path| "#{path}/**/[0-9]*_*.rb" }]
- end
-
def current_environment
ActiveRecord::ConnectionHandling::DEFAULT_ENV.call
end
@@ -1145,6 +1136,15 @@ module ActiveRecord
end
private
+ def migration_files
+ paths = Array(migrations_paths)
+ Dir[*paths.flat_map { |path| "#{path}/**/[0-9]*_*.rb" }]
+ end
+
+ def parse_migration_filename(filename)
+ File.basename(filename).scan(Migration::MigrationFilenameRegexp).first
+ end
+
def move(direction, steps)
migrator = Migrator.new(direction, migrations)