Sha256: 83a8385f47eaef52755008177bd1a13ec0de3ad51835c25aebc10795f6432c68

Contents?: true

Size: 754 Bytes

Versions: 11

Compression:

Stored size: 754 Bytes

Contents

class CreateDefaultStock < ActiveRecord::Migration
  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

11 entries across 11 versions & 1 rubygems

Version Path
solidus_core-1.4.2 db/migrate/20130213191427_create_default_stock.rb
solidus_core-1.3.2 db/migrate/20130213191427_create_default_stock.rb
solidus_core-1.4.1 db/migrate/20130213191427_create_default_stock.rb
solidus_core-1.4.0 db/migrate/20130213191427_create_default_stock.rb
solidus_core-1.4.0.rc1 db/migrate/20130213191427_create_default_stock.rb
solidus_core-1.4.0.beta1 db/migrate/20130213191427_create_default_stock.rb
solidus_core-1.3.1 db/migrate/20130213191427_create_default_stock.rb
solidus_core-1.3.0 db/migrate/20130213191427_create_default_stock.rb
solidus_core-1.3.0.rc2 db/migrate/20130213191427_create_default_stock.rb
solidus_core-1.3.0.rc1 db/migrate/20130213191427_create_default_stock.rb
solidus_core-1.3.0.beta1 db/migrate/20130213191427_create_default_stock.rb