socialforge/db/migrate/20150814031258_update_cours...

27 lines
835 B
Ruby

class UpdateCourseActivityTime < ActiveRecord::Migration
def up
count = CourseActivity.all.count / 30 + 1
transaction do
for i in 1 ... count do i
CourseActivity.page(i).per(30).each do |activity|
if activity.course_act
if activity.course_act.respond_to?("created_at")
activity.created_at = activity.course_act.created_at
elsif activity.course_act.respond_to?("created_on")
activity.created_at = activity.course_act.created_on
end
activity.save
user_activity = UserActivity.where("act_type = '#{activity.course_act_type.to_s}' and act_id = '#{activity.course_act_id}'").first
user_activity.created_at = activity.created_at
user_activity.save
end
end
end
end
end
def down
end
end