diff options
author | Cristi Balan <evil@che.lu> | 2009-08-08 17:39:31 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-08-08 17:41:43 +0100 |
commit | 7f84f14efabf3e342a231b8aa9650cb484c802d6 (patch) | |
tree | fe96f90e6e8f2fcbad0c69f92f9b7e8bfa49f6b9 /activerecord | |
parent | c284412b149e03f46144ef566bcd6a16750961b1 (diff) | |
download | rails-7f84f14efabf3e342a231b8aa9650cb484c802d6.tar.gz rails-7f84f14efabf3e342a231b8aa9650cb484c802d6.tar.bz2 rails-7f84f14efabf3e342a231b8aa9650cb484c802d6.zip |
Add rake db:forward - opposite of db:rollback [#768 state:resolved]
Example:
rake db:forward # performs the next migration
rake db:forward STEP=4 # performs the next 4 migrations
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/migration.rb | 10 | ||||
-rw-r--r-- | activerecord/test/cases/migration_test.rb | 11 |
2 files changed, 21 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index 3963baa6b8..d205e57db3 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -397,6 +397,16 @@ module ActiveRecord down(migrations_path, finish ? finish.version : 0) end + def forward(migrations_path, steps=1) + migrator = self.new(:up, migrations_path) + start_index = migrator.migrations.index(migrator.current_migration) + + return unless start_index + + finish = migrator.migrations[start_index + steps] + up(migrations_path, finish ? finish.version : 0) + end + def up(migrations_path, target_version = nil) self.new(:up, migrations_path, target_version).migrate end diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 72d4892435..f0f21615e0 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -1136,6 +1136,17 @@ if ActiveRecord::Base.connection.supports_migrations? assert_equal(0, ActiveRecord::Migrator.current_version) end + def test_migrator_forward + ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid", 1) + assert_equal(1, ActiveRecord::Migrator.current_version) + + ActiveRecord::Migrator.forward(MIGRATIONS_ROOT + "/valid", 2) + assert_equal(3, ActiveRecord::Migrator.current_version) + + ActiveRecord::Migrator.forward(MIGRATIONS_ROOT + "/valid") + assert_equal(3, ActiveRecord::Migrator.current_version) + end + def test_schema_migrations_table_name ActiveRecord::Base.table_name_prefix = "prefix_" ActiveRecord::Base.table_name_suffix = "_suffix" |