Sha256: 81bd32f5b2b678e2edc13dfc7f82b2017863c4808d843a0e8321a185a4346bb5

Contents?: true

Size: 861 Bytes

Versions: 20

Compression:

Stored size: 861 Bytes

Contents

class PolymorphicPayments < ActiveRecord::Migration
  def self.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
      t.string :payment_method
      t.references :source, :polymorphic => true
    end
    execute "UPDATE payments SET payable_type = 'Order'"

    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

    change_table :creditcards do |t|
      t.remove :checkout_id
    end 
  end

  def self.down
    # no going back!
  end
end

Version data entries

20 entries across 20 versions & 3 rubygems

Version Path
spree-0.11.4 db/migrate/20100209144531_polymorphic_payments.rb
spree-0.11.3 db/migrate/20100209144531_polymorphic_payments.rb
spree_core-0.30.2 db/migrate/20100209144531_polymorphic_payments.rb
spree_core-0.40.4 db/migrate/20100209144531_polymorphic_payments.rb
spree_essential_press-0.1.0.pre3 test/dummy/db/migrate/20100209144531_polymorphic_payments.rb
spree_essential_press-0.1.0.pre2 test/dummy/db/migrate/20100209144531_polymorphic_payments.rb
spree_core-0.40.3 db/migrate/20100209144531_polymorphic_payments.rb
spree_core-0.40.2 db/migrate/20100209144531_polymorphic_payments.rb
spree_core-0.40.1 db/migrate/20100209144531_polymorphic_payments.rb
spree_core-0.40.0 db/migrate/20100209144531_polymorphic_payments.rb
spree_core-0.30.1 db/migrate/20100209144531_polymorphic_payments.rb
spree_core-0.30.0 db/migrate/20100209144531_polymorphic_payments.rb
spree-0.11.2 db/migrate/20100209144531_polymorphic_payments.rb
spree-0.11.1 db/migrate/20100209144531_polymorphic_payments.rb
spree_core-0.30.0.beta1 lib/generators/templates/db/migrate/20100209144531_polymorphic_payments.rb
spree-0.11.0 db/migrate/20100209144531_polymorphic_payments.rb
spree-0.10.2 db/migrate/20100209144531_polymorphic_payments.rb
spree-0.10.1 db/migrate/20100209144531_polymorphic_payments.rb
spree-0.10.0 db/migrate/20100209144531_polymorphic_payments.rb
spree-0.10.0.beta db/migrate/20100209144531_polymorphic_payments.rb