class UpdateActivity < ActiveRecord::Migration
  def up
    homeworks = HomeworkCommon.where("course_id = 342")
    unless homeworks.nil?
      homeworks.each do |h|
        course_activity = CourseActivity.where("course_act_type=? and course_act_id =?", 'HomeworkCommon', h.id).first
        user_activity = UserActivity.where("act_type=? and act_id =?", 'HomeworkCommon', h.id).first
        org_activity = OrgActivity.where("org_act_type=? and org_act_id =?", 'HomeworkCommon', h.id).first
        if course_activity && h.updated_at > course_activity.updated_at
          course_activity.update_column('updated_at', h.updated_at)
        end
        if user_activity && h.updated_at > user_activity.updated_at
          user_activity.update_column('updated_at', h.updated_at)
        end
        if org_activity && h.updated_at > org_activity.updated_at
          org_activity.update_column('updated_at', h.updated_at)
        end
      end
    end
  end

  def down
  end
end
