diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-10-03 16:39:48 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-10-03 16:39:48 -0700 |
commit | 365c93b7cdaa161c77c157c7cc385221ebbc33c7 (patch) | |
tree | ecb3380a79f62f9255049ec5a89d25059a2d6351 | |
parent | 40761c4bf39826254b7a5266210f91742591f58c (diff) | |
download | rails-365c93b7cdaa161c77c157c7cc385221ebbc33c7.tar.gz rails-365c93b7cdaa161c77c157c7cc385221ebbc33c7.tar.bz2 rails-365c93b7cdaa161c77c157c7cc385221ebbc33c7.zip |
speed up duplicate migration detection
-rw-r--r-- | activerecord/lib/active_record/migration.rb | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index 3bfd1851b5..7a1504430b 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -507,6 +507,8 @@ module ActiveRecord def migrations(path) files = Dir["#{path}/[0-9]*_*.rb"] + seen = Hash.new false + migrations = files.inject([]) do |klasses, file| version, name, scope = file.scan(/([0-9]+)_([_a-z0-9]*)\.?([_a-z0-9]*)?.rb/).first name = name.camelize @@ -514,13 +516,10 @@ module ActiveRecord raise IllegalMigrationNameError.new(file) unless version version = version.to_i - if klasses.detect { |m| m.version == version } - raise DuplicateMigrationVersionError.new(version) - end + raise DuplicateMigrationVersionError.new(version) if seen[version] + raise DuplicateMigrationNameError.new(name) if seen[[name, scope]] - if klasses.detect { |m| m.name == name && m.scope == scope } - raise DuplicateMigrationNameError.new(name) - end + seen[version] = seen[[name, scope]] = true migration = MigrationProxy.new(name, version, file, scope) klasses << migration |