Sha256: ab486eaad3832e679cb95e8863523cf9015728b82f7749f4b74aa9624881da7b

Contents?: true

Size: 1.07 KB

Versions: 14

Compression:

Stored size: 1.07 KB

Contents

# This migration comes from spree (originally 20121031162139)
class SplitPricesFromVariants < ActiveRecord::Migration
  def up
    create_table :spree_prices do |t|
      t.integer :variant_id, :null => false
      t.decimal :amount, :precision => 8, :scale => 2, :null => false
      t.string :currency
    end

    Spree::Variant.all.each do |variant|
      Spree::Price.create!(
        :variant_id => variant.id,
        :amount => variant[:price],
        :currency => Spree::Config[:currency]
      )
    end

    remove_column :spree_variants, :price
  end

  def down
    prices = ActiveRecord::Base.connection.execute("select variant_id, amount from spree_prices")
    add_column :spree_variants, :price, :decimal, :after => :sku, :scale => 2, :precision => 8

    prices.each do |price|
      ActiveRecord::Base.connection.execute("update spree_variants set price = #{price['amount']} where id = #{price['variant_id']}")
    end
    
    change_column :spree_variants, :price, :decimal, :after => :sku, :scale => 2, :precision => 8, :null => false
    drop_table :spree_prices
  end
end

Version data entries

14 entries across 14 versions & 7 rubygems

Version Path
spree_weight_calculator-0.1.0 test/dummy/db/migrate/20160723192441_split_prices_from_variants.spree.rb
spree_order_reporting-0.0.3 spec/dummy/db/migrate/20160708163038_split_prices_from_variants.spree.rb
spree_order_reporting-0.0.2 spec/dummy/db/migrate/20160707103362_split_prices_from_variants.spree.rb
spree_order_reporting-0.0.1 spec/dummy/db/migrate/20160706112314_split_prices_from_variants.spree.rb
sprangular-0.1.0 spec/dummy/db/migrate/20140814105640_split_prices_from_variants.spree.rb
sprangular-0.0.1 spec/dummy/db/migrate/20140814105640_split_prices_from_variants.spree.rb
spree_mercado_pago-0.2.3 spec/dummy/db/migrate/20141204014633_split_prices_from_variants.spree.rb
spree_mercado_pago-0.2.2 spec/dummy/db/migrate/20141204014633_split_prices_from_variants.spree.rb
spree_mercado_pago-0.2.1 spec/dummy/db/migrate/20141112193416_split_prices_from_variants.spree.rb
spree_mercado_pago-0.2.0 spec/dummy/db/migrate/20141112193416_split_prices_from_variants.spree.rb
spree_mercado_pago_payment_method-0.2.0 spec/dummy/db/migrate/20141112193416_split_prices_from_variants.spree.rb
spree_bitpay-1.0.2 spec/dummy/db/migrate/20141002181213_split_prices_from_variants.spree.rb
bcms_spree-0.0.2 test/dummy/db/migrate/20140915222552_split_prices_from_variants.spree.rb
bcms_spree-0.0.1 test/dummy/db/migrate/20140915222552_split_prices_from_variants.spree.rb