]> cat aescling's git repositories - mastodon.git/commitdiff
Fix ActiveRecord::Migration.check_pending! failing because of duplicate migrations
authorThibaut Girka <thib@sitedethib.com>
Mon, 10 Feb 2020 18:03:14 +0000 (19:03 +0100)
committerThibG <thib@sitedethib.com>
Mon, 10 Feb 2020 19:04:41 +0000 (20:04 +0100)
config/initializers/0_duplicate_migrations.rb

index 4ab806587e626a76c8b72d313b4d8fe0953a3af9..194aff70cb0c03e88c2df533db93916ca897c33f 100644 (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