Sha256: d6f3befc0116c8ee02026ebd0b058804aeadae48362b84c3dd322408735d8c31

Contents?: true

Size: 612 Bytes

Versions: 9

Compression:

Stored size: 612 Bytes

Contents

# This migration comes from spree (originally 20140805171219)
class MakeExistingCreditCardsDefault < ActiveRecord::Migration[4.2]
  def up
    # set the newest credit card for every user to be the default; SQL technique from
    # http://stackoverflow.com/questions/121387/fetch-the-row-which-has-the-max-value-for-a-column
    Spree::CreditCard.where.not(user_id: nil).joins("LEFT OUTER JOIN spree_credit_cards cc2 ON cc2.user_id = spree_credit_cards.user_id AND spree_credit_cards.created_at < cc2.created_at").where("cc2.user_id IS NULL").update_all(default: true)
  end
  def down
    # do nothing
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
spree_purchase_order-3.7.0 spec/dummy/db/migrate/20191113195885_make_existing_credit_cards_default.spree.rb
spree_billing_sisow-0.9.2 spec/dummy/db/migrate/20190729091826_make_existing_credit_cards_default.spree.rb
spree_billing_sisow-0.9.1 spec/dummy/db/migrate/20190729091826_make_existing_credit_cards_default.spree.rb
spree_purchase_order-3.6.0 spec/dummy/db/migrate/20180516182014_make_existing_credit_cards_default.spree.rb
spree_purchase_order-3.5.0 spec/dummy/db/migrate/20180516182014_make_existing_credit_cards_default.spree.rb
spree_purchase_order-3.5.0.rc1 spec/dummy/db/migrate/20180516182014_make_existing_credit_cards_default.spree.rb
spree_purchase_order-3.4.0 spec/dummy/db/migrate/20180516182014_make_existing_credit_cards_default.spree.rb
spree_purchase_order-3.3.0 spec/dummy/db/migrate/20180516182014_make_existing_credit_cards_default.spree.rb
spree_purchase_order-3.2.0 spec/dummy/db/migrate/20180516182014_make_existing_credit_cards_default.spree.rb