public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Fix migrations when migrating to a specified version number with a fresh 
database [#1 state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
ianwhite (author)
Thu Apr 17 11:43:47 -0700 2008
josh (committer)
Thu Apr 17 11:43:47 -0700 2008
commit  82b4faf81218bbd8916ab559590db236c7f80e46
tree    e5b65fae3a5d54c93f660f2b56980acb86d5ff68
parent  9e1d506a8cfedef2fdd605e4cbf4bf53651ad214
...
364
365
366
367
368
 
 
 
 
369
370
371
...
364
365
366
 
 
367
368
369
370
371
372
373
0
@@ -364,8 +364,10 @@ module ActiveRecord
0
       end
0
 
0
       def current_version
0
-        Base.connection.select_values(
0
-          "SELECT version FROM #{schema_migrations_table_name}").map(&:to_i).max || 0
0
+        version = Base.connection.select_values(
0
+          "SELECT version FROM #{schema_migrations_table_name}"
0
+        ).map(&:to_i).max rescue nil
0
+        version || 0
0
       end
0
 
0
       def proper_table_name(name)
...
813
814
815
 
 
 
 
 
 
 
816
817
818
...
1010
1011
1012
1013
 
1014
1015
1016
...
813
814
815
816
817
818
819
820
821
822
823
824
825
...
1017
1018
1019
 
1020
1021
1022
1023
0
@@ -813,6 +813,13 @@ if ActiveRecord::Base.connection.supports_migrations?
0
       end
0
     end
0
 
0
+    def test_migrator_db_has_no_schema_migrations_table
0
+      ActiveRecord::Base.connection.execute("DROP TABLE schema_migrations;")
0
+      assert_nothing_raised do
0
+        ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid", 1)
0
+      end
0
+    end
0
+
0
     def test_migrator_verbosity
0
       ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid", 1)
0
       assert PeopleHaveLastNames.message_count > 0
0
@@ -1010,7 +1017,7 @@ if ActiveRecord::Base.connection.supports_migrations?
0
       end
0
 
0
   end
0
-
0
+  
0
   uses_mocha 'Sexy migration tests' do
0
     class SexyMigrationsTest < ActiveRecord::TestCase
0
       def test_references_column_type_adds_id

Comments