Sha256: fde41d43f7c7e28378efc76e9d508b7cb06b3f63ce0bca0ef6b518432dfd69d8
Contents?: true
Size: 943 Bytes
Versions: 2
Compression:
Stored size: 943 Bytes
Contents
# This migration comes from spree (originally 20150528125647) class DeleteInventoryUnitsWithoutShipment < ActiveRecord::Migration # Prevent everything from running in one giant transaction in postrgres. disable_ddl_transaction! def up order_ids = Spree::InventoryUnit.where(shipment_id: nil).pluck(:order_id).uniq.compact Spree::Order.where(id: order_ids).find_each do |order| # Order may not be completed but have shipped # shipments if it has a pending unreturned exchange next if order.completed? next if order.canceled? next if order.shipments.any? { |s| s.shipped? || s.ready? || s.canceled? } say "Removing inventory units without shipment for order ##{order.number}" order.transaction do order.inventory_units.destroy_all order.shipments.destroy_all order.restart_checkout_flow end end end def down # intentionally left blank end end
Version data entries
2 entries across 2 versions & 1 rubygems