Browse files

making rake:migrate VERSION=0 a noop called in succession. [#2137 sta…

…te:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent ce5af2f commit dcf0f97514851face2dd24b1f39eabee413fcfc2 Neeraj Singh committed with josevalim Apr 20, 2010
Showing with 20 additions and 0 deletions.
  1. +1 −0 activerecord/lib/active_record/migration.rb
  2. +19 −0 activerecord/test/cases/migration_test.rb
View
1 activerecord/lib/active_record/migration.rb
@@ -381,6 +381,7 @@ class << self
def migrate(migrations_path, target_version = nil)
case
when target_version.nil? then up(migrations_path, target_version)
+ when current_version == 0 && target_version == 0 then # noop
when current_version > target_version then down(migrations_path, target_version)
else up(migrations_path, target_version)
end
View
19 activerecord/test/cases/migration_test.rb
@@ -1077,6 +1077,25 @@ def test_only_loads_pending_migrations
load(MIGRATIONS_ROOT + "/valid/1_people_have_last_names.rb")
end
+ def test_target_version_zero_should_run_only_once
+ # migrate up to 1
+ ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid", 1)
+
+ # migrate down to 0
+ ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid", 0)
+
+ # now unload the migrations that have been defined
+ PeopleHaveLastNames.unloadable
+ ActiveSupport::Dependencies.remove_unloadable_constants!
+
+ # migrate down to 0 again
+ ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid", 0)
+
+ assert !defined? PeopleHaveLastNames
+ ensure
+ load(MIGRATIONS_ROOT + "/valid/1_people_have_last_names.rb")
+ end
+
def test_migrator_interleaved_migrations
ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/interleaved/pass_1")

0 comments on commit dcf0f97

Please sign in to comment.