Permalink
Browse files

Compare migrations for copying only by name and scope

  • Loading branch information...
1 parent ed0b1f6 commit 929b2646b606e639a127bdd17f1aad169a26e2c5 @drogus drogus committed Dec 9, 2011
Showing with 7 additions and 48 deletions.
  1. +6 −22 activerecord/lib/active_record/migration.rb
  2. +1 −26 activerecord/test/cases/migration_test.rb
@@ -457,28 +457,28 @@ def copy(destination, sources, options = {})
destination_migrations = ActiveRecord::Migrator.migrations(destination)
last = destination_migrations.last
- sources.each do |name, path|
+ sources.each do |scope, path|
source_migrations = ActiveRecord::Migrator.migrations(path)
source_migrations.each do |migration|
source = File.read(migration.filename)
- source = "# This migration comes from #{name} (originally #{migration.version})\n#{source}"
+ source = "# This migration comes from #{scope} (originally #{migration.version})\n#{source}"
if duplicate = destination_migrations.detect { |m| m.name == migration.name }
- if options[:on_skip] && !migrations_identical?(File.read(duplicate.filename), source)
- options[:on_skip].call(name, migration)
+ if options[:on_skip] && duplicate.scope != scope.to_s
+ options[:on_skip].call(scope, migration)
end
next
end
migration.version = next_migration_number(last ? last.version + 1 : 0).to_i
- new_path = File.join(destination, "#{migration.version}_#{migration.name.underscore}.#{name}.rb")
+ new_path = File.join(destination, "#{migration.version}_#{migration.name.underscore}.#{scope}.rb")
old_path, migration.filename = migration.filename, new_path
last = migration
File.open(migration.filename, "w") { |f| f.write source }
copied << migration
- options[:on_copy].call(name, migration, old_path) if options[:on_copy]
+ options[:on_copy].call(scope, migration, old_path) if options[:on_copy]
destination_migrations << migration
end
end
@@ -493,22 +493,6 @@ def next_migration_number(number)
"%.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.lines.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
@@ -2226,7 +2226,7 @@ def test_skipping_migrations
clear
end
- def test_skip_is_not_called_if_migrations_are_identical
+ def test_skip_is_not_called_if_migrations_are_from_the_same_plugin
@migrations_path = MIGRATIONS_ROOT + "/valid_with_timestamps"
@existing_migrations = Dir[@migrations_path + "/*.rb"]
@@ -2244,31 +2244,6 @@ def test_skip_is_not_called_if_migrations_are_identical
clear
end
- def test_skip_ignores_origin_comment
- ActiveRecord::Base.timestamped_migrations = false
- @migrations_path = MIGRATIONS_ROOT + "/valid"
- @existing_migrations = Dir[@migrations_path + "/*.rb"]
-
- sources = ActiveSupport::OrderedHash.new
- sources[:bukkits] = MIGRATIONS_ROOT + "/to_copy"
-
- skipped = []
- on_skip = Proc.new { |name, migration| skipped << "#{name} #{migration.name}" }
- copied = ActiveRecord::Migration.copy(@migrations_path, sources, :on_skip => on_skip)
-
- # remove origin comment
- migration = @migrations_path + "/4_people_have_hobbies.bukkits.rb"
- migration_source = File.read(migration).lines.to_a[1..-1].join
- File.open(migration, "w") { |f| f.write migration_source }
-
- ActiveRecord::Migration.copy(@migrations_path, sources, :on_skip => on_skip)
-
- assert_equal 2, copied.length
- assert_equal 0, skipped.length
- ensure
- clear
- end
-
def test_copying_migrations_to_non_existing_directory
@migrations_path = MIGRATIONS_ROOT + "/non_existing"
@existing_migrations = []

0 comments on commit 929b264

Please sign in to comment.