1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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.
This commit is contained in:
Ryuta Kamizono 2018-12-28 10:03:04 +09:00
parent c1b14aded2
commit 22a6ff68b1
2 changed files with 11 additions and 13 deletions

View file

@ -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)})"

View file

@ -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)