class SetPriorityForOrgSubfields < ActiveRecord::Migration
  def up
    Organization.all.each do |org|
      org.transaction do
        org.org_subfields.where("field_type='default'").each do|field|
          case field.name
            when 'activity'
              field.update_attribute(:priority, 1)
            when 'course'
              field.update_attribute(:priority, 2)
            when 'project'
              field.update_attribute(:priority, 3)
          end
        end
        org.org_subfields.where("field_type!='default'").each_with_index do  |field, index|
          field.update_attribute(:priority, index + 4)
        end
      end
    end
  end

  def down
  end
end
