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>
This commit is contained in:
parent
c284412b14
commit
7f84f14efa
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -172,6 +172,13 @@ namespace :db do
|
|||
Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
|
||||
end
|
||||
|
||||
desc 'Pushes the schema to the next version. Specify the number of steps with STEP=n'
|
||||
task :forward => :environment do
|
||||
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
|
||||
ActiveRecord::Migrator.forward('db/migrate/', step)
|
||||
Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
|
||||
end
|
||||
|
||||
desc 'Drops and recreates the database from db/schema.rb for the current environment and loads the seeds.'
|
||||
task :reset => [ 'db:drop', 'db:setup' ]
|
||||
|
||||
|
|
Loading…
Reference in New Issue