Method: Migr8::RepositoryOperation#upgrade

Defined in:
lib/migr8.rb

#upgrade(n) ⇒ Object



464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
# File 'lib/migr8.rb', line 464

def upgrade(n)
  migs_hist, migs_dict = _get_migrations_hist_and_applied()
  ## index of current version
  curr = migs_hist.rindex {|mig| mig.applied? }
  ## error when unapplied older version exists
  if curr
    j = migs_hist.index {|mig| ! mig.applied? }
    raise MigrationError.new("apply #{migs_hist[j].version} at first.") if j && j < curr
  end
  ## unapplied migrations
  migs_unapplied = curr ? migs_hist[(curr+1)..-1] : migs_hist
  ## apply n migrations
  migs_to_apply = n.nil? ? migs_unapplied : migs_unapplied[0...n]
  if migs_to_apply.empty?
    puts "## (nothing to apply)"
  else
    #migs_to_apply.each do |mig|
    #  puts "## applying #{mig.version}  \# [#{mig.author}] #{mig.desc}"
    #  @repo.apply_migration(mig)
    #end
    @repo.apply_migrations(migs_to_apply)
  end
end