ActiveRecord::Migrator#run records version-state after migrating. [#369 state:resolved]
This commit is contained in:
parent
1afae84ab2
commit
f94600bdaf
|
@ -1,5 +1,7 @@
|
||||||
*Edge*
|
*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]
|
* 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]
|
* MySQL: rename_column preserves column defaults. #466 [Diego Algorta]
|
||||||
|
|
|
@ -399,7 +399,10 @@ module ActiveRecord
|
||||||
def run
|
def run
|
||||||
target = migrations.detect { |m| m.version == @target_version }
|
target = migrations.detect { |m| m.version == @target_version }
|
||||||
raise UnknownMigrationVersionError.new(@target_version) if target.nil?
|
raise UnknownMigrationVersionError.new(@target_version) if target.nil?
|
||||||
|
unless (up? && migrated.include?(target.version.to_i)) || (down? && !migrated.include?(target.version.to_i))
|
||||||
target.migrate(@direction)
|
target.migrate(@direction)
|
||||||
|
record_version_state_after_migrating(target.version)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def migrate
|
def migrate
|
||||||
|
|
|
@ -825,6 +825,21 @@ if ActiveRecord::Base.connection.supports_migrations?
|
||||||
assert !Reminder.table_exists?
|
assert !Reminder.table_exists?
|
||||||
end
|
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
|
def test_finds_migrations
|
||||||
migrations = ActiveRecord::Migrator.new(:up, MIGRATIONS_ROOT + "/valid").migrations
|
migrations = ActiveRecord::Migrator.new(:up, MIGRATIONS_ROOT + "/valid").migrations
|
||||||
[['1', 'people_have_last_names'],
|
[['1', 'people_have_last_names'],
|
||||||
|
@ -915,16 +930,6 @@ if ActiveRecord::Base.connection.supports_migrations?
|
||||||
assert_equal(0, ActiveRecord::Migrator.current_version)
|
assert_equal(0, ActiveRecord::Migrator.current_version)
|
||||||
end
|
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
|
def test_schema_migrations_table_name
|
||||||
ActiveRecord::Base.table_name_prefix = "prefix_"
|
ActiveRecord::Base.table_name_prefix = "prefix_"
|
||||||
ActiveRecord::Base.table_name_suffix = "_suffix"
|
ActiveRecord::Base.table_name_suffix = "_suffix"
|
||||||
|
|
Loading…
Reference in New Issue