Sha256: b19ac837348fe027bf7d5787f69d11c0ffbb97b450d219de8a17f263554b4b36

Contents?: true

Size: 1.1 KB

Versions: 10

Compression:

Stored size: 1.1 KB

Contents

# This migration comes from spree (originally 20130213191427)
class CreateDefaultStock < ActiveRecord::Migration
  def up
    Spree::StockLocation.skip_callback(:create, :after, :create_stock_items)
    Spree::StockItem.skip_callback(:save, :after, :process_backorders)
    location = Spree::StockLocation.new(name: 'default')
    location.save(validate: false)

    Spree::Variant.find_each do |variant|
      stock_item = Spree::StockItem.unscoped.build(stock_location: location, variant: variant)
      stock_item.send(:count_on_hand=, variant.count_on_hand)
      # Avoid running default_scope defined by acts_as_paranoid, related to #3805,
      # validations would run a query with a delete_at column that might not be present yet
      stock_item.save! validate: false
    end

    remove_column :spree_variants, :count_on_hand
  end

  def down
    add_column :spree_variants, :count_on_hand, :integer

    Spree::StockItem.find_each do |stock_item|
      stock_item.variant.update_column :count_on_hand, stock_item.count_on_hand
    end

    Spree::StockLocation.delete_all
    Spree::StockItem.delete_all
  end
end

Version data entries

10 entries across 10 versions & 5 rubygems

Version Path
sprangular-0.1.0 spec/dummy/db/migrate/20140814105656_create_default_stock.spree.rb
sprangular-0.0.1 spec/dummy/db/migrate/20140814105656_create_default_stock.spree.rb
spree_mercado_pago-0.2.3 spec/dummy/db/migrate/20141204014649_create_default_stock.spree.rb
spree_mercado_pago-0.2.2 spec/dummy/db/migrate/20141204014649_create_default_stock.spree.rb
spree_mercado_pago-0.2.1 spec/dummy/db/migrate/20141112193432_create_default_stock.spree.rb
spree_mercado_pago-0.2.0 spec/dummy/db/migrate/20141112193432_create_default_stock.spree.rb
spree_mercado_pago_payment_method-0.2.0 spec/dummy/db/migrate/20141112193432_create_default_stock.spree.rb
spree_bitpay-1.0.2 spec/dummy/db/migrate/20141002181229_create_default_stock.spree.rb
bcms_spree-0.0.2 test/dummy/db/migrate/20140915222568_create_default_stock.spree.rb
bcms_spree-0.0.1 test/dummy/db/migrate/20140915222568_create_default_stock.spree.rb