Override Migrator.new instead of Migrator#initialize, it's easier to understand
This commit is contained in:
		
							parent
							
								
									13f738e229
								
							
						
					
					
						commit
						562534a9d3
					
				
					 1 changed files with 2 additions and 4 deletions
				
			
		| 
						 | 
					@ -16,9 +16,7 @@ ALLOWED_DUPLICATES = [20180410220657, 20180831171112].freeze
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module ActiveRecord
 | 
					module ActiveRecord
 | 
				
			||||||
  class Migrator
 | 
					  class Migrator
 | 
				
			||||||
    old_initialize = instance_method(:initialize)
 | 
					    def self.new(direction, migrations, target_version = nil)
 | 
				
			||||||
 | 
					 | 
				
			||||||
    define_method(:initialize) do |direction, migrations, target_version|
 | 
					 | 
				
			||||||
      migrated = Set.new(Base.connection.migration_context.get_all_versions)
 | 
					      migrated = Set.new(Base.connection.migration_context.get_all_versions)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      migrations.group_by(&:name).each do |name, duplicates|
 | 
					      migrations.group_by(&:name).each do |name, duplicates|
 | 
				
			||||||
| 
						 | 
					@ -36,7 +34,7 @@ module ActiveRecord
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      old_initialize.bind(self).(direction, migrations, target_version)
 | 
					      super(direction, migrations, target_version)
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue