diff options
author | Michael Raidel <raidel@induktiv.at> | 2008-06-13 16:14:07 +0200 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-06-22 18:16:17 -0700 |
commit | f94600bdaf7d73971ad9a53148b0844c2efb901d (patch) | |
tree | 12be24df5ae0336cb8b1c9d4a6f4882b007e6e78 | |
parent | 1afae84ab2656cd58a861ab4a4b1745d80088d0f (diff) | |
download | rails-f94600bdaf7d73971ad9a53148b0844c2efb901d.tar.gz rails-f94600bdaf7d73971ad9a53148b0844c2efb901d.tar.bz2 rails-f94600bdaf7d73971ad9a53148b0844c2efb901d.zip |
ActiveRecord::Migrator#run records version-state after migrating. [#369 state:resolved]
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/migration.rb | 5 | ||||
-rw-r--r-- | activerecord/test/cases/migration_test.rb | 25 |
3 files changed, 21 insertions, 11 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index df62f3fbf7..0ac5ce960c 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *Edge* +* 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] diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index b47b01e99a..e095b3c766 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -399,7 +399,10 @@ module ActiveRecord 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 diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 2cac7f04ab..fe7fa7ba03 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -825,6 +825,21 @@ if ActiveRecord::Base.connection.supports_migrations? 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'], @@ -914,16 +929,6 @@ if ActiveRecord::Base.connection.supports_migrations? 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_" |