Skip to content

Commit

Permalink
making rake:migrate VERSION=0 a noop called in succession. [#2137 sta…
Browse files Browse the repository at this point in the history
…te:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
Neeraj Singh authored and josevalim committed Apr 29, 2010
1 parent 68c96fa commit f4d174b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
10 changes: 7 additions & 3 deletions activerecord/lib/active_record/migration.rb
Expand Up @@ -384,9 +384,13 @@ class Migrator#:nodoc:
class << self
def migrate(migrations_path, target_version = nil)
case
when target_version.nil? then up(migrations_path, target_version)
when current_version > target_version then down(migrations_path, target_version)
else up(migrations_path, target_version)
when target_version.nil?
up(migrations_path, target_version)
when current_version == 0 && target_version == 0
when current_version > target_version
down(migrations_path, target_version)
else
up(migrations_path, target_version)
end
end

Expand Down
19 changes: 19 additions & 0 deletions activerecord/test/cases/migration_test.rb
Expand Up @@ -1136,6 +1136,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_db_has_no_schema_migrations_table
# Oracle adapter raises error if semicolon is present as last character
if current_adapter?(:OracleAdapter)
Expand Down

0 comments on commit f4d174b

Please sign in to comment.