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 version = version.to_i
sm_table = quote_table_name(ActiveRecord::SchemaMigration.table_name) sm_table = quote_table_name(ActiveRecord::SchemaMigration.table_name)
migrated = ActiveRecord::SchemaMigration.all_versions.map(&:to_i) migrated = migration_context.get_all_versions
versions = migration_context.migration_files.map do |file| versions = migration_context.migrations.map(&:version)
migration_context.parse_migration_filename(file).first.to_i
end
unless migrated.include?(version) unless migrated.include?(version)
execute "INSERT INTO #{sm_table} (version) VALUES (#{quote(version)})" execute "INSERT INTO #{sm_table} (version) VALUES (#{quote(version)})"

View file

@ -1087,10 +1087,6 @@ module ActiveRecord
migrations.last || NullMigration.new migrations.last || NullMigration.new
end end
def parse_migration_filename(filename) # :nodoc:
File.basename(filename).scan(Migration::MigrationFilenameRegexp).first
end
def migrations def migrations
migrations = migration_files.map do |file| migrations = migration_files.map do |file|
version, name, scope = parse_migration_filename(file) version, name, scope = parse_migration_filename(file)
@ -1122,11 +1118,6 @@ module ActiveRecord
(db_list + file_list).sort_by { |_, version, _| version } (db_list + file_list).sort_by { |_, version, _| version }
end end
def migration_files
paths = Array(migrations_paths)
Dir[*paths.flat_map { |path| "#{path}/**/[0-9]*_*.rb" }]
end
def current_environment def current_environment
ActiveRecord::ConnectionHandling::DEFAULT_ENV.call ActiveRecord::ConnectionHandling::DEFAULT_ENV.call
end end
@ -1145,6 +1136,15 @@ module ActiveRecord
end end
private 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) def move(direction, steps)
migrator = Migrator.new(direction, migrations) migrator = Migrator.new(direction, migrations)