Sha256: dc3f854732e0385d1cc14d7cdf1cf0a309f168410ead8b3ddf1ddcb93fe371f2

Contents?: true

Size: 687 Bytes

Versions: 20

Compression:

Stored size: 687 Bytes

Contents

class AssignCreditcardTxnsToPayment < ActiveRecord::Migration
  def self.up
    add_column "creditcard_txns", "payment_id", :integer  
    ActiveRecord::Base.connection.select_all("SELECT * FROM creditcard_txns").each do |txn_attrs|
      if creditcard = Creditcard.find_by_id(txn_attrs["creditcard_id"]) and creditcard.payments.first
        execute "UPDATE creditcard_txns SET payment_id = #{creditcard.payments.first.id} WHERE id = #{txn_attrs['id']}"
      end
    end
    remove_column "creditcard_txns", "creditcard_payment_id"
  end

  def self.down
    remove_column "creditcard_txns", "payment_id"
    add_column "creditcard_txns", "creditcard_payment_id", :integer  
  end
end

Version data entries

20 entries across 20 versions & 3 rubygems

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