aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/migration.rb
diff options
context:
space:
mode:
authorPiotr Sarnacki <drogus@gmail.com>2011-12-09 01:49:08 +0100
committerPiotr Sarnacki <drogus@gmail.com>2011-12-09 01:54:20 +0100
commit62d556424adcbf473ec5fe2ed9b460c058a36463 (patch)
tree681e6a6f447c798abadcc51933120ad8271f3e9b /activerecord/lib/active_record/migration.rb
parent652db2fc3e1d62737e4bedb3b7cee313d7400c0a (diff)
downloadrails-62d556424adcbf473ec5fe2ed9b460c058a36463.tar.gz
rails-62d556424adcbf473ec5fe2ed9b460c058a36463.tar.bz2
rails-62d556424adcbf473ec5fe2ed9b460c058a36463.zip
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.
Diffstat (limited to 'activerecord/lib/active_record/migration.rb')
-rw-r--r--activerecord/lib/active_record/migration.rb22
1 files changed, 20 insertions, 2 deletions
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