public
Fork of rails/rails
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/aslakhellesoy/rails.git
Detect duplicate migration names when running migrations. This can happen if a 
migration is renamed after it is created
aslakhellesoy (author)
Tue May 06 22:59:34 -0700 2008
commit  14c03ba619960693ec73fad7833d1a00562e2c64
tree    e997a35ebdc3a47f78c9259c74093fb246173ad3
parent  0a21193dc660396fb993b06d1d3c168a9cd900a5
...
8
9
10
 
 
 
 
 
 
11
12
13
...
440
441
442
 
 
 
 
443
444
445
...
8
9
10
11
12
13
14
15
16
17
18
19
...
446
447
448
449
450
451
452
453
454
455
0
@@ -8,6 +8,12 @@ module ActiveRecord
0
     end
0
   end
0
 
0
+  class DuplicateMigrationNameError < ActiveRecordError#:nodoc:
0
+    def initialize(name)
0
+      super("Multiple migrations have the name #{name}")
0
+    end
0
+  end
0
+
0
   class UnknownMigrationVersionError < ActiveRecordError #:nodoc:
0
     def initialize(version)
0
       super("No migration with version number #{version}")
0
@@ -440,6 +446,10 @@ module ActiveRecord
0
           if klasses.detect { |m| m.version == version }
0
             raise DuplicateMigrationVersionError.new(version) 
0
           end
0
+
0
+          if klasses.detect { |m| m.name == name.camelize }
0
+            raise DuplicateMigrationNameError.new(name.camelize) 
0
+          end
0
           
0
           load(file)
0
           
...
984
985
986
 
 
 
 
 
 
987
988
989
...
984
985
986
987
988
989
990
991
992
993
994
995
0
@@ -984,6 +984,12 @@ if ActiveRecord::Base.connection.supports_migrations?
0
       end
0
     end
0
 
0
+    def test_migrator_with_duplicate_names
0
+      assert_raises(ActiveRecord::DuplicateMigrationNameError, "Multiple migrations have the name Chunky") do
0
+        ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/duplicate_names", nil)
0
+      end
0
+    end
0
+
0
     def test_migrator_with_missing_version_numbers
0
       assert_raise(ActiveRecord::UnknownMigrationVersionError) do
0
         ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/missing", 500)

Comments