488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
|
# File 'lib/migr8.rb', line 488
def downgrade(n)
migs_hist, migs_dict = _get_migrations_hist_and_applied()
curr = migs_hist.rindex {|mig| mig.applied? }
migs_applied = curr ? migs_hist[0..curr] : []
if curr
j = migs_applied.index {|mig| ! mig.applied? }
raise MigrationError.new("apply #{migs_applied[j].version} at first.") if j && j < curr
end
migs_to_unapply = n && n < migs_applied.length ? migs_applied[-n..-1] \
: migs_applied
if migs_to_unapply.empty?
puts "## (nothing to unapply)"
else
@repo.unapply_migrations(migs_to_unapply.reverse())
end
end
|