about summary refs log tree commit diff
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2020-02-10 19:03:14 +0100
committerThibG <thib@sitedethib.com>2020-02-10 20:04:41 +0100
commit2edf317efc26f11632ea46bd9168f8c997be7180 (patch)
tree32f78f21ae3f83c2bda1f2897488f83be824a3bb
parent3d7fd4a2df0bb88dccb931b0731022333aa9810d (diff)
Fix ActiveRecord::Migration.check_pending! failing because of duplicate migrations
-rw-r--r--config/initializers/0_duplicate_migrations.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/config/initializers/0_duplicate_migrations.rb b/config/initializers/0_duplicate_migrations.rb
index 4ab806587..194aff70c 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