Sha256: 3ed03990d6b748a8be13b347ce39c0cf90c863e31f18c631a3d422cd98739fb1

Contents?: true

Size: 551 Bytes

Versions: 21

Compression:

Stored size: 551 Bytes

Contents

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

21 entries across 21 versions & 1 rubygems

Version Path
solidus_core-2.3.1 db/migrate/20140805171219_make_existing_credit_cards_default.rb
solidus_core-2.2.2 db/migrate/20140805171219_make_existing_credit_cards_default.rb
solidus_core-2.1.1 db/migrate/20140805171219_make_existing_credit_cards_default.rb
solidus_core-2.0.3 db/migrate/20140805171219_make_existing_credit_cards_default.rb
solidus_core-2.3.0 db/migrate/20140805171219_make_existing_credit_cards_default.rb
solidus_core-2.3.0.rc3 db/migrate/20140805171219_make_existing_credit_cards_default.rb
solidus_core-2.3.0.rc2 db/migrate/20140805171219_make_existing_credit_cards_default.rb
solidus_core-2.3.0.rc1 db/migrate/20140805171219_make_existing_credit_cards_default.rb
solidus_core-2.3.0.beta1 db/migrate/20140805171219_make_existing_credit_cards_default.rb
solidus_core-2.0.2 db/migrate/20140805171219_make_existing_credit_cards_default.rb
solidus_core-2.2.1 db/migrate/20140805171219_make_existing_credit_cards_default.rb
solidus_core-2.2.0 db/migrate/20140805171219_make_existing_credit_cards_default.rb
solidus_core-2.2.0.rc1 db/migrate/20140805171219_make_existing_credit_cards_default.rb
solidus_core-2.2.0.beta1 db/migrate/20140805171219_make_existing_credit_cards_default.rb
solidus_core-2.1.0 db/migrate/20140805171219_make_existing_credit_cards_default.rb
solidus_core-2.1.0.rc1 db/migrate/20140805171219_make_existing_credit_cards_default.rb
solidus_core-2.0.1 db/migrate/20140805171219_make_existing_credit_cards_default.rb
solidus_core-2.1.0.beta1 db/migrate/20140805171219_make_existing_credit_cards_default.rb
solidus_core-2.0.0 db/migrate/20140805171219_make_existing_credit_cards_default.rb
solidus_core-2.0.0.rc1 db/migrate/20140805171219_make_existing_credit_cards_default.rb