Sha256: fad3ab316bbfbae196d6d723c0580fc8c07431e052e4bf7467e94d75fe1a0676

Contents?: true

Size: 1.62 KB

Versions: 7

Compression:

Stored size: 1.62 KB

Contents

# This migration comes from spree (originally 20091021133257)
class Checkout < ActiveRecord::Base; end;

# Hack to prevent issues with legacy migrations
class Order < ActiveRecord::Base
  has_one :checkout
end

class ChargeRefactoring < ActiveRecord::Migration
  def up
    # Temporarily set table name for legacy support
    Spree::Adjustment.table_name = 'adjustments'

    add_column :orders, :completed_at, :timestamp
    Order.reset_column_information
    Order.all.each { |o| o.update_column(:completed_at, o.checkout && o.checkout.read_attribute(:completed_at)) }
    remove_column :checkouts, :completed_at

    change_column :adjustments, :amount, :decimal, :null => true, :default => nil, :precision => 8, :scale => 2
    Spree::Adjustment.update_all :type => 'secondary_type'
    Spree::Adjustment.where(:type => 'Credit').update_all(:type => 'CouponCredit')
    remove_column :adjustments, :secondary_type

    # Reset table name
    Spree::Adjustment.table_name = 'spree_adjustments'
  end

  def down
    add_column :checkouts, :completed_at, :timestamp
    Spree::Checkout.reset_column_information
    Spree::Checkout.all.each { |c| c.update_column(:completed_at, c.order && c.order.completed_at) }
    remove_column :orders, :completed_at

    add_column :adjustments, :secondary_type, :string
    Spree::Adjustment.update_all :secondary_type => 'type'
    Spree::Adjustment.where('type LIKE ?', '%Charge').update_all(:type => 'Charge')
    Spree::Adjustment.where('type LIKE ?', '%Credit').update_all(:type => 'Credit')
    change_column :adjustments, :amount, :decimal, :null => false, :default => 0, :precision => 8, :scale => 2
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
spree_mercado_pago_payment_method-0.0.2 spec/dummy/db/migrate/20121121030149_charge_refactoring.spree.rb
spree_mercado_pago_payment_method-0.1.1 spec/dummy/db/migrate/20121121030149_charge_refactoring.spree.rb
spree_mercado_pago_payment_method-0.1.0 spec/dummy/db/migrate/20121121030149_charge_refactoring.spree.rb
datashift_spree-0.3.0 spec/sandbox/db/migrate/20121023154368_charge_refactoring.spree.rb
datashift_spree-0.2.1 spec/sandbox/db/migrate/20121015151161_charge_refactoring.spree.rb
datashift_spree-0.2.0 spec/sandbox/db/migrate/20120925192729_charge_refactoring.spree.rb
datashift_spree-0.1.0 spec/sandbox/db/migrate/20120918081460_charge_refactoring.spree.rb