Fix ActiveRecord::Migration.check_pending! failing because of duplicate migrations

lolsob-rspec
Thibaut Girka 2020-02-10 19:03:14 +01:00 committed by ThibG
parent b93d4d2b2a
commit 7f034cf429
1 changed files with 12 additions and 0 deletions

View File

@ -37,4 +37,16 @@ module ActiveRecord
super(direction, migrations, target_version)
end
end
class MigrationContext
def needs_migration?
# A set of duplicated migrations is considered migrated if at least one of
# them is migrated.
migrated = get_all_versions
migrations.group_by(&:name).each do |name, duplicates|
return true unless duplicates.any? { |m| migrated.include?(m.version.to_i) }
end
return false
end
end
end