class AddClientIdToShippingBoxes < ActiveRecord::Migration[6.0]
  def change
    add_column :shipping_boxes, :client_id, :integer
    add_index  :shipping_boxes, :client_id
    ShippingBox.find_each do |shipping_box|
      order = Order.where(sn: shipping_box.po).first
      if order
        shipping_box.update_columns(client_id: order.client_id)
      end
    end
  end
end
