Permalink
Browse files

Fix migrations when migrating to a specified version number with a fr…

…esh database [#1 state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information...
ianwhite authored and josh committed Apr 17, 2008
1 parent 9e1d506 commit 82b4faf81218bbd8916ab559590db236c7f80e46
Showing with 12 additions and 3 deletions.
  1. +4 −2 activerecord/lib/active_record/migration.rb
  2. +8 −1 activerecord/test/cases/migration_test.rb
@@ -364,8 +364,10 @@ def schema_migrations_table_name
end
def current_version
- Base.connection.select_values(
- "SELECT version FROM #{schema_migrations_table_name}").map(&:to_i).max || 0
+ version = Base.connection.select_values(
+ "SELECT version FROM #{schema_migrations_table_name}"
+ ).map(&:to_i).max rescue nil
+ version || 0
end
def proper_table_name(name)
@@ -813,6 +813,13 @@ def test_migrator_interleaved_migrations
end
end
+ def test_migrator_db_has_no_schema_migrations_table
+ ActiveRecord::Base.connection.execute("DROP TABLE schema_migrations;")
+ assert_nothing_raised do
+ ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid", 1)
+ end
+ end
+
def test_migrator_verbosity
ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid", 1)
assert PeopleHaveLastNames.message_count > 0
@@ -1010,7 +1017,7 @@ def with_env_tz(new_tz = 'US/Eastern')
end
end
-
+
uses_mocha 'Sexy migration tests' do
class SexyMigrationsTest < ActiveRecord::TestCase
def test_references_column_type_adds_id

0 comments on commit 82b4faf

Please sign in to comment.