class AddLastTermToCourse < ActiveRecord::Migration def change add_column :courses, :end_time, :integer add_column :courses, :end_term, :string count = Course.all.count / 30 + 2 transaction do for i in 1 ... count do Course.page(i).per(30).each do |course| course.end_time = course.time course.end_term = course.term course.save end end end end end