Sha256: 5bb83a3c328840fc4811f0968b649ec9016b09f356eb0893cc0c12ed54357ce4

Contents?: true

Size: 1.15 KB

Versions: 107

Compression:

Stored size: 1.15 KB

Contents

class AddOriginalReturnItemIdToSpreeInventoryUnits < ActiveRecord::Migration[5.0]
  def up
    add_reference :spree_inventory_units, :original_return_item, references: :spree_return_items, index: true

    Spree::InventoryUnit.reset_column_information

    Spree::ReturnItem.where.not(exchange_inventory_unit_id: nil).find_each do |return_item|
      if (inventory_unit = Spree::InventoryUnit.find_by(id: return_item.exchange_inventory_unit_id)).present?
        inventory_unit.update_column(:original_return_item_id, return_item.id)
      end
    end

    remove_column :spree_return_items, :exchange_inventory_unit_id
  end

  def down
    add_reference :spree_return_items, :exchange_inventory_unit, references: :spree_inventory_units, index: true

    Spree::InventoryUnit.reset_column_information

    Spree::InventoryUnit.where.not(original_return_item_id: nil).find_each do |inventory_unit|
      if (return_item = Spree::ReturnItem.find_by(id: inventory_unit.original_return_item_id)).present?
        return_item.update_column(:exchange_inventory_unit_id, inventory_unit.id)
      end
    end

    remove_reference :spree_inventory_units, :original_return_item
  end
end

Version data entries

107 entries across 107 versions & 1 rubygems

Version Path
spree_core-4.0.9 db/migrate/20170119122701_add_original_return_item_id_to_spree_inventory_units.rb
spree_core-4.1.15 db/migrate/20170119122701_add_original_return_item_id_to_spree_inventory_units.rb
spree_core-4.2.7 db/migrate/20170119122701_add_original_return_item_id_to_spree_inventory_units.rb
spree_core-4.3.3 db/migrate/20170119122701_add_original_return_item_id_to_spree_inventory_units.rb
spree_core-4.2.6 db/migrate/20170119122701_add_original_return_item_id_to_spree_inventory_units.rb
spree_core-4.3.2 db/migrate/20170119122701_add_original_return_item_id_to_spree_inventory_units.rb
spree_core-4.3.1 db/migrate/20170119122701_add_original_return_item_id_to_spree_inventory_units.rb
spree_core-4.3.0 db/migrate/20170119122701_add_original_return_item_id_to_spree_inventory_units.rb
spree_core-4.3.0.rc3 db/migrate/20170119122701_add_original_return_item_id_to_spree_inventory_units.rb
spree_core-4.3.0.rc2 db/migrate/20170119122701_add_original_return_item_id_to_spree_inventory_units.rb
spree_core-4.3.0.rc1 db/migrate/20170119122701_add_original_return_item_id_to_spree_inventory_units.rb
spree_core-4.2.5 db/migrate/20170119122701_add_original_return_item_id_to_spree_inventory_units.rb
spree_core-4.1.14 db/migrate/20170119122701_add_original_return_item_id_to_spree_inventory_units.rb
spree_core-4.0.8 db/migrate/20170119122701_add_original_return_item_id_to_spree_inventory_units.rb
spree_core-4.2.4 db/migrate/20170119122701_add_original_return_item_id_to_spree_inventory_units.rb
spree_core-3.7.14.1 db/migrate/20170119122701_add_original_return_item_id_to_spree_inventory_units.rb
spree_core-4.2.3.1 db/migrate/20170119122701_add_original_return_item_id_to_spree_inventory_units.rb
spree_core-4.1.13.1 db/migrate/20170119122701_add_original_return_item_id_to_spree_inventory_units.rb
spree_core-4.0.7.1 db/migrate/20170119122701_add_original_return_item_id_to_spree_inventory_units.rb
spree_core-4.2.3 db/migrate/20170119122701_add_original_return_item_id_to_spree_inventory_units.rb