Sha256: c8560cbefeb4bb60eaa1e7d9558d592afe148203db95753eb147ac2cbf974b13

Contents?: true

Size: 743 Bytes

Versions: 15

Compression:

Stored size: 743 Bytes

Contents

class MigrateCreditCardsToWalletPaymentSources < ActiveRecord::Migration[4.2]
  class CreditCard < ActiveRecord::Base
    self.table_name = 'spree_credit_cards'
  end
  class WalletPaymentSource < ActiveRecord::Base
    self.table_name = 'spree_wallet_payment_sources'
  end

  def up
    credit_cards = CreditCard.
      where.not(gateway_customer_profile_id: nil).
      where.not(user_id: nil)

    credit_cards.find_each do |credit_card|
      WalletPaymentSource.find_or_create_by!(
        user_id: credit_card.user_id,
        payment_source_id: credit_card.id,
        payment_source_type: 'Spree::CreditCard'
      ) do |wallet_source|
        wallet_source.default = credit_card.default
      end
    end
  end

  def down
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
solidus_core-2.5.2 db/migrate/20160420181916_migrate_credit_cards_to_wallet_payment_sources.rb
solidus_core-2.5.1 db/migrate/20160420181916_migrate_credit_cards_to_wallet_payment_sources.rb
solidus_core-2.5.0 db/migrate/20160420181916_migrate_credit_cards_to_wallet_payment_sources.rb
solidus_core-2.5.0.rc1 db/migrate/20160420181916_migrate_credit_cards_to_wallet_payment_sources.rb
solidus_core-2.5.0.beta2 db/migrate/20160420181916_migrate_credit_cards_to_wallet_payment_sources.rb
solidus_core-2.5.0.beta1 db/migrate/20160420181916_migrate_credit_cards_to_wallet_payment_sources.rb
solidus_core-2.4.2 db/migrate/20160420181916_migrate_credit_cards_to_wallet_payment_sources.rb
solidus_core-2.3.1 db/migrate/20160420181916_migrate_credit_cards_to_wallet_payment_sources.rb
solidus_core-2.2.2 db/migrate/20160420181916_migrate_credit_cards_to_wallet_payment_sources.rb
solidus_core-2.3.0 db/migrate/20160420181916_migrate_credit_cards_to_wallet_payment_sources.rb
solidus_core-2.3.0.rc3 db/migrate/20160420181916_migrate_credit_cards_to_wallet_payment_sources.rb
solidus_core-2.3.0.rc2 db/migrate/20160420181916_migrate_credit_cards_to_wallet_payment_sources.rb
solidus_core-2.3.0.rc1 db/migrate/20160420181916_migrate_credit_cards_to_wallet_payment_sources.rb
solidus_core-2.3.0.beta1 db/migrate/20160420181916_migrate_credit_cards_to_wallet_payment_sources.rb
solidus_core-2.2.1 db/migrate/20160420181916_migrate_credit_cards_to_wallet_payment_sources.rb