Sha256: d964ed02f96d67b89720a235f526e6f8b8633f65ac7f5659987a0a1680f42d3f

Contents?: true

Size: 1.29 KB

Versions: 28

Compression:

Stored size: 1.29 KB

Contents

# Legacy table support
class Checkout < ActiveRecord::Base; end;

class PolymorphicPayments < ActiveRecord::Migration
  def up
    remove_column :payments, :type
    remove_column :payments, :creditcard_id
    rename_column :payments, :order_id, :payable_id
    change_table :payments do |t|
      t.string :payable_type, :payment_method
      t.references :source, :polymorphic => true
    end
    execute "UPDATE payments SET payable_type = 'Order'"

    Spree::Creditcard.table_name = 'creditcards'

    Spree::Creditcard.all.each do |creditcard|
      if checkout = Checkout.find_by_id(creditcard.checkout_id) and checkout.order
        if payment = checkout.order.payments.first
          execute "UPDATE payments SET source_type = 'Creditcard', source_id = #{creditcard.id} WHERE id = #{payment.id}"
        end
      end
    end

    Spree::Creditcard.table_name = 'spree_creditcards'

    remove_column :creditcards, :checkout_id
  end

  def down
    add_column :creditcards, :checkout_id, :integer
    change_table :payments do |t|
      t.remove :payable_type
      t.remove :payment_method
      t.remove :source_id
      t.remove :source_type
    end
    rename_column :payments, :payable_id, :order_id
    add_column :payments, :creditcard_id, :integer
    add_column :payments, :type, :string
  end
end

Version data entries

28 entries across 28 versions & 3 rubygems

Version Path
spree_core-1.1.6 db/migrate/20100209144531_polymorphic_payments.rb
spree_core-1.1.5 db/migrate/20100209144531_polymorphic_payments.rb
spree_core-1.0.7 db/migrate/20100209144531_polymorphic_payments.rb
spree_core-1.1.4 db/migrate/20100209144531_polymorphic_payments.rb
spree_core-1.1.3 db/migrate/20100209144531_polymorphic_payments.rb
spree_core-1.0.6 db/migrate/20100209144531_polymorphic_payments.rb
spree_pag_seguro-1.0.7 spec/dummy/db/migrate/20120301154080_polymorphic_payments.rb
spree_core-1.1.2 db/migrate/20100209144531_polymorphic_payments.rb
spree_core-1.1.2.rc1 db/migrate/20100209144531_polymorphic_payments.rb
spree_pag_seguro-1.0.6 spec/dummy/db/migrate/20120301154080_polymorphic_payments.rb
spree_pag_seguro-1.0.5 spec/dummy/db/migrate/20120301154080_polymorphic_payments.rb
spree_pag_seguro-1.0.4 spec/dummy/db/migrate/20120301154080_polymorphic_payments.rb
spree_core-1.1.1 db/migrate/20100209144531_polymorphic_payments.rb
spree_core-1.1.0 db/migrate/20100209144531_polymorphic_payments.rb
spree_core-1.0.4 db/migrate/20100209144531_polymorphic_payments.rb
spree_core-1.1.0.rc2 db/migrate/20100209144531_polymorphic_payments.rb
spree_core-1.1.0.rc1 db/migrate/20100209144531_polymorphic_payments.rb
spree_pag_seguro-1.0.3 spec/dummy/db/migrate/20120301154080_polymorphic_payments.rb
spree_pag_seguro-1.0.2 spec/dummy/db/migrate/20120301154080_polymorphic_payments.rb
spree_core-1.0.3 db/migrate/20100209144531_polymorphic_payments.rb