<commit_before>class AddShippingMethodToLineItems < ActiveRecord::Migration
  def up
    add_column :spree_line_items, :shipping_method_id, :integer

    Spree::LineItem.all.each do |li|
      begin
        shipping_method = li.product.shipping_method_for_distributor(li.order.distributor)
      rescue ArgumentError
        shipping_method = Spree::ShippingMethod.find_by_name 'Producer Delivery'
      end

      Spree::LineItem.update_all("shipping_method_id = #{shipping_method.id}", "id = #{li.id}")
    end
  end

  def down
    remove_column :spree_line_items, :shipping_method_id
  end
end<commit_msg>Add debug output on line item migration for lost data<commit_after>class AddShippingMethodToLineItems < ActiveRecord::Migration
  def up
    add_column :spree_line_items, :shipping_method_id, :integer

    Spree::LineItem.all.each do |li|
      begin
        shipping_method = li.product.shipping_method_for_distributor(li.order.distributor)
      rescue ArgumentError
        shipping_method = Spree::ShippingMethod.find_by_name 'Producer Delivery'
        say "Line item #{li.id} does not have a valid shipping method, setting to '#{shipping_method.name}'"
      end

      Spree::LineItem.update_all("shipping_method_id = #{shipping_method.id}", "id = #{li.id}")
    end
  end

  def down
    remove_column :spree_line_items, :shipping_method_id
  end
end
{'fraction_non_alphanumeric': 0.08705193855157278, 'fraction_numerical': 0.0, 'mean_word_length': 4.142857142857143, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6344778', 'n_tokens_mistral': 441, 'n_tokens_neox': 438, 'n_words': 92}