Sha256: bf9b6be2ed3bc36a13ec76d2148c45624dcc42c1833656d3d051488925514aca
Contents?: true
Size: 834 Bytes
Versions: 6
Compression:
Stored size: 834 Bytes
Contents
class RemoveOrderIdFromInventoryUnits < ActiveRecord::Migration[5.0] class InconsistentInventoryUnitError < StandardError; end class InventoryUnit < ActiveRecord::Base self.table_name = "spree_inventory_units" belongs_to :shipment end class Shipment < ActiveRecord::Base self.table_name = "spree_shipments" has_many :inventory_units end def up if InventoryUnit. joins(:shipment). where.not( 'spree_inventory_units.order_id = spree_shipments.order_id' ).exists? raise InconsistentInventoryUnitError, "You have inventory units with inconsistent order references. Please fix those before running this migration" end remove_column :spree_inventory_units, :order_id end def down add_reference :spree_inventory_units, :order, index: true end end
Version data entries
6 entries across 6 versions & 1 rubygems