Skip to content

Commit

Permalink
ActiveRecord::Migrator#run records version-state after migrating. [#369
Browse files Browse the repository at this point in the history
… state:resolved]
  • Loading branch information
mraidel authored and jeremy committed Jun 23, 2008
1 parent b31b6ef commit 7839a83
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
2 changes: 2 additions & 0 deletions activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*2.1.1 (next release)*

* db:migrate:down and :up update schema_migrations. #369 [Michael Raidel, RaceCondition]

* PostgreSQL: support :conditions => [':foo::integer', { :foo => 1 }] without treating the ::integer typecast as a bind variable. [Tarmo Tänav]

* MySQL: rename_column preserves column defaults. #466 [Diego Algorta]
Expand Down
5 changes: 4 additions & 1 deletion activerecord/lib/active_record/migration.rb
Expand Up @@ -399,7 +399,10 @@ def current_migration
def run
target = migrations.detect { |m| m.version == @target_version }
raise UnknownMigrationVersionError.new(@target_version) if target.nil?
target.migrate(@direction)
unless (up? && migrated.include?(target.version.to_i)) || (down? && !migrated.include?(target.version.to_i))
target.migrate(@direction)
record_version_state_after_migrating(target.version)
end
end

def migrate
Expand Down
25 changes: 15 additions & 10 deletions activerecord/test/cases/migration_test.rb
Expand Up @@ -825,6 +825,21 @@ def test_migrator_one_up_one_down
assert !Reminder.table_exists?
end

def test_migrator_double_up
assert_equal(0, ActiveRecord::Migrator.current_version)
ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT + "/valid", 1)
assert_nothing_raised { ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT + "/valid", 1) }
assert_equal(1, ActiveRecord::Migrator.current_version)
end

def test_migrator_double_down
assert_equal(0, ActiveRecord::Migrator.current_version)
ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT + "/valid", 1)
ActiveRecord::Migrator.run(:down, MIGRATIONS_ROOT + "/valid", 1)
assert_nothing_raised { ActiveRecord::Migrator.run(:down, MIGRATIONS_ROOT + "/valid", 1) }
assert_equal(0, ActiveRecord::Migrator.current_version)
end

def test_finds_migrations
migrations = ActiveRecord::Migrator.new(:up, MIGRATIONS_ROOT + "/valid").migrations
[['1', 'people_have_last_names'],
Expand Down Expand Up @@ -914,16 +929,6 @@ def test_migrator_rollback
ActiveRecord::Migrator.rollback(MIGRATIONS_ROOT + "/valid")
assert_equal(0, ActiveRecord::Migrator.current_version)
end

def test_migrator_run
assert_equal(0, ActiveRecord::Migrator.current_version)
ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT + "/valid", 3)
assert_equal(0, ActiveRecord::Migrator.current_version)

assert_equal(0, ActiveRecord::Migrator.current_version)
ActiveRecord::Migrator.run(:down, MIGRATIONS_ROOT + "/valid", 3)
assert_equal(0, ActiveRecord::Migrator.current_version)
end

def test_schema_migrations_table_name
ActiveRecord::Base.table_name_prefix = "prefix_"
Expand Down

0 comments on commit 7839a83

Please sign in to comment.