class CopyCourseActivitiesToOrgActivities < ActiveRecord::Migration
  def up
    count = CourseActivity.all.count/30 + 1
    for i in 1 ... count do
      transaction do
        CourseActivity.page(i).per(30).each do |course_act|
          if course_act.course_act_type == 'Message' && !course_act.course_act.parent_id.nil?
            org_activity = OrgActivity.where("org_act_type = 'Message' and org_act_id = #{course_act.course_act.parent.id}").first
            org_activity.created_at = course_act.created_at
            org_activity.save
          else
            OrgActivity.create(:user_id => course_act.user_id,
                               :org_act_id => course_act.course_act_id,
                               :org_act_type => course_act.course_act_type,
                               :container_id => course_act.course_id,
                               :container_type => 'Course',
                               :created_at => course_act.created_at,
                               :updated_at => course_act.updated_at)
          end
        end
      end
    end
  end

  def down
  end
end
