From 2edf317efc26f11632ea46bd9168f8c997be7180 Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Mon, 10 Feb 2020 19:03:14 +0100 Subject: [PATCH] Fix ActiveRecord::Migration.check_pending! failing because of duplicate migrations --- config/initializers/0_duplicate_migrations.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/config/initializers/0_duplicate_migrations.rb b/config/initializers/0_duplicate_migrations.rb index 4ab806587e6..194aff70cb0 100644 --- a/config/initializers/0_duplicate_migrations.rb +++ b/config/initializers/0_duplicate_migrations.rb @@ -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