Sha256: 3aa401abf59de6ecea2bf6c633a9283f2a41c9d64bbe3b876f751d55ea1887ce

Contents?: true

Size: 419 Bytes

Versions: 3

Compression:

Stored size: 419 Bytes

Contents

class AddPriceToLineItem < ActiveRecord::Migration
  def up
    Piggybak::LineItem.class_eval do
      self.table_name = 'line_items'
    end

    add_column :line_items, :price, :decimal, :null => false, :default => 0.0
    Piggybak::LineItem.all.each do |line_item|
      line_item.update_attribute(:price, line_item.total/line_item.quantity)
    end
  end

  def down
    remove_column :line_items, :price
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
piggybak-0.7.7 db/migrate/20120627144001_add_price_to_line_item.rb
piggybak-0.7.6 db/migrate/20120627144001_add_price_to_line_item.rb
piggybak-0.7.5 db/migrate/20120627144001_add_price_to_line_item.rb