Sha256: 21b8bb6858661a4821e2fb141a3d770064b2c42bef28862edce62c27e4eae830

Contents?: true

Size: 759 Bytes

Versions: 21

Compression:

Stored size: 759 Bytes

Contents

class CreateDefaultStock < ActiveRecord::Migration[4.2]
  class Variant < ActiveRecord::Base
    self.table_name = 'spree_variants'
  end
  class StockLocation < ActiveRecord::Base
    self.table_name = 'spree_stock_locations'
  end
  class StockItem < ActiveRecord::Base
    self.table_name = 'spree_stock_items'
  end

  def up
    unless column_exists? :spree_stock_locations, :default
      add_column :spree_stock_locations, :default, :boolean, null: false, default: false
    end

    location = StockLocation.create!(name: 'default')

    Spree::Variant.find_each do |variant|
      StockItem.create!(stock_location: location, variant: variant, count_on_hand: variant.count_on_hand)
    end

    remove_column :spree_variants, :count_on_hand
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
solidus_core-2.3.1 db/migrate/20130213191427_create_default_stock.rb
solidus_core-2.2.2 db/migrate/20130213191427_create_default_stock.rb
solidus_core-2.1.1 db/migrate/20130213191427_create_default_stock.rb
solidus_core-2.0.3 db/migrate/20130213191427_create_default_stock.rb
solidus_core-2.3.0 db/migrate/20130213191427_create_default_stock.rb
solidus_core-2.3.0.rc3 db/migrate/20130213191427_create_default_stock.rb
solidus_core-2.3.0.rc2 db/migrate/20130213191427_create_default_stock.rb
solidus_core-2.3.0.rc1 db/migrate/20130213191427_create_default_stock.rb
solidus_core-2.3.0.beta1 db/migrate/20130213191427_create_default_stock.rb
solidus_core-2.0.2 db/migrate/20130213191427_create_default_stock.rb
solidus_core-2.2.1 db/migrate/20130213191427_create_default_stock.rb
solidus_core-2.2.0 db/migrate/20130213191427_create_default_stock.rb
solidus_core-2.2.0.rc1 db/migrate/20130213191427_create_default_stock.rb
solidus_core-2.2.0.beta1 db/migrate/20130213191427_create_default_stock.rb
solidus_core-2.1.0 db/migrate/20130213191427_create_default_stock.rb
solidus_core-2.1.0.rc1 db/migrate/20130213191427_create_default_stock.rb
solidus_core-2.0.1 db/migrate/20130213191427_create_default_stock.rb
solidus_core-2.1.0.beta1 db/migrate/20130213191427_create_default_stock.rb
solidus_core-2.0.0 db/migrate/20130213191427_create_default_stock.rb
solidus_core-2.0.0.rc1 db/migrate/20130213191427_create_default_stock.rb