public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
ActiveRecord::Migrator#run records version-state after migrating.  [#369 
state:resolved]
Michael Raidel (author)
Fri Jun 13 07:14:07 -0700 2008
jeremy (committer)
Sun Jun 22 18:16:17 -0700 2008
commit  f94600bdaf7d73971ad9a53148b0844c2efb901d
tree    12be24df5ae0336cb8b1c9d4a6f4882b007e6e78
parent  1afae84ab2656cd58a861ab4a4b1745d80088d0f
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *Edge*
0
 
0
+* db:migrate:down and :up update schema_migrations.  #369 [Michael Raidel, RaceCondition]
0
+
0
 * PostgreSQL: support :conditions => [':foo::integer', { :foo => 1 }] without treating the ::integer typecast as a bind variable.  [Tarmo Tänav]
0
 
0
 * MySQL: rename_column preserves column defaults.  #466 [Diego Algorta]
...
399
400
401
402
 
 
 
 
403
404
405
...
399
400
401
 
402
403
404
405
406
407
408
0
@@ -399,7 +399,10 @@ module ActiveRecord
0
     def run
0
       target = migrations.detect { |m| m.version == @target_version }
0
       raise UnknownMigrationVersionError.new(@target_version) if target.nil?
0
-      target.migrate(@direction)
0
+      unless (up? && migrated.include?(target.version.to_i)) || (down? && !migrated.include?(target.version.to_i))
0
+        target.migrate(@direction)
0
+        record_version_state_after_migrating(target.version)
0
+      end
0
     end
0
 
0
     def migrate
...
825
826
827
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
828
829
830
...
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
...
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
...
929
930
931
 
 
 
 
 
 
 
 
 
 
932
933
934
0
@@ -825,6 +825,21 @@ if ActiveRecord::Base.connection.supports_migrations?
0
       assert !Reminder.table_exists?
0
     end
0
 
0
+    def test_migrator_double_up
0
+      assert_equal(0, ActiveRecord::Migrator.current_version)
0
+      ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT + "/valid", 1)
0
+      assert_nothing_raised { ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT + "/valid", 1) }
0
+      assert_equal(1, ActiveRecord::Migrator.current_version)
0
+    end
0
+
0
+    def test_migrator_double_down
0
+      assert_equal(0, ActiveRecord::Migrator.current_version)
0
+      ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT + "/valid", 1)
0
+      ActiveRecord::Migrator.run(:down, MIGRATIONS_ROOT + "/valid", 1)
0
+      assert_nothing_raised { ActiveRecord::Migrator.run(:down, MIGRATIONS_ROOT + "/valid", 1) }
0
+      assert_equal(0, ActiveRecord::Migrator.current_version)
0
+    end
0
+
0
     def test_finds_migrations
0
       migrations = ActiveRecord::Migrator.new(:up, MIGRATIONS_ROOT + "/valid").migrations
0
       [['1', 'people_have_last_names'],
0
@@ -914,16 +929,6 @@ if ActiveRecord::Base.connection.supports_migrations?
0
       ActiveRecord::Migrator.rollback(MIGRATIONS_ROOT + "/valid")
0
       assert_equal(0, ActiveRecord::Migrator.current_version)
0
     end
0
-    
0
-    def test_migrator_run
0
-      assert_equal(0, ActiveRecord::Migrator.current_version)
0
-      ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT + "/valid", 3)
0
-      assert_equal(0, ActiveRecord::Migrator.current_version)
0
-
0
-      assert_equal(0, ActiveRecord::Migrator.current_version)
0
-      ActiveRecord::Migrator.run(:down, MIGRATIONS_ROOT + "/valid", 3)
0
-      assert_equal(0, ActiveRecord::Migrator.current_version)
0
-    end
0
 
0
     def test_schema_migrations_table_name
0
       ActiveRecord::Base.table_name_prefix = "prefix_"

Comments