-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1765 from jhawthorn/wallet_migration
Migrate all reusable credit card to wallet sources
- Loading branch information
Showing
2 changed files
with
26 additions
and
30 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
core/db/migrate/20160420181916_migrate_credit_cards_to_wallet_payment_sources.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
30 changes: 0 additions & 30 deletions
30
core/db/migrate/20160420181916_move_credit_card_default_to_wallet_payment_source.rb
This file was deleted.
Oops, something went wrong.