From 62d556424adcbf473ec5fe2ed9b460c058a36463 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 9 Dec 2011 01:49:08 +0100 Subject: Ignore origin comment when checking for duplicates on Migration.copy 49ebe51 fixed copying migrations, but existing migrations would still trigger warnings. The proper way to compare migrations is to ignore origin lines - if migration is identical it means that we can silently skip it, regardless where it comes from. --- activerecord/lib/active_record/migration.rb | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record/migration.rb') diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index 1d450da006..102a523744 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -461,11 +461,13 @@ module ActiveRecord source_migrations = ActiveRecord::Migrator.migrations(path) source_migrations.each do |migration| - source = File.read(migration.filename).chomp + source = File.read(migration.filename) source = "# This migration comes from #{name} (originally #{migration.version})\n#{source}" if duplicate = destination_migrations.detect { |m| m.name == migration.name } - options[:on_skip].call(name, migration) if File.read(duplicate.filename).chomp != source && options[:on_skip] + if options[:on_skip] && !migrations_identical?(File.read(duplicate.filename), source) + options[:on_skip].call(name, migration) + end next end @@ -491,6 +493,22 @@ module ActiveRecord "%.3d" % number end end + + def migrations_identical?(a, b) + # Due to a bug some of the migrations copied may not have origin comment, + # so we need to ignore it. + remove_origin_comment(a.chomp) == remove_origin_comment(b.chomp) + end + private :migrations_identical? + + def remove_origin_comment(migration_source) + if migration_source =~ /^# This migration comes from/ + migration_source = migration_source.to_a[1..-1].join + end + + migration_source + end + private :remove_origin_comment end # MigrationProxy is used to defer loading of the actual migration classes -- cgit v1.2.3