Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate all reusable credit card to wallet sources #1765

Merged
merged 1 commit into from
Mar 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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: credit_card
) do |wallet_source|
wallet_source.default = credit_card.default
end
end
end

def down
end
end

This file was deleted.