class ReorderCooImgPosition < ActiveRecord::Migration[5.2]
  def change
    CooImg.all.group_by(&:img_type).each do |_type, objs|
      objs.sort_by(&:position).each_with_index do |obj, index|
        obj.update!(position: index + 1)
      end
    end
  end
end
