<commit_before>class CombineItemsInCart < ActiveRecord::Migration
  
  def up
    Cart.all.each do |cart|
      sums = cart.line_items.group(:product_id).sum(:quantity)

      sums.each do |product_id, quantity|
        if quantity > 1
          
          cart.line_items.where(product_id: product_id).delete_all
          
          item = cart.line_items.build(product_id: product_id)
          item.quantity = quantity
          item.save!

        end
      end
    end
  end

end<commit_msg>Add to migration 'down' method<commit_after>class CombineItemsInCart < ActiveRecord::Migration
  
  def up
    Cart.all.each do |cart|
      sums = cart.line_items.group(:product_id).sum(:quantity)

      sums.each do |product_id, quantity|
        if quantity > 1
          
          cart.line_items.where(product_id: product_id).delete_all
          
          item = cart.line_items.build(product_id: product_id)
          item.quantity = quantity
          item.save!

        end
      end
    end
  end

  def down
    LineItem.where("quantity>1").each do |line_item|
    
      line_item.quantity.times do 
        LineItem.create cart_id: line_item.cart_id, product_id: line_item.product_id, quantity: 1
      end

      line_item.destroy
    end
  end

end
{'fraction_non_alphanumeric': 0.08234362628661916, 'fraction_numerical': 0.003167062549485352, 'mean_word_length': 2.1679197994987467, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '7243265', 'n_tokens_mistral': 406, 'n_tokens_neox': 389, 'n_words': 81}