Sha256: b809004c8ac6563920dc8751d897842a40f48894651cc6b62812f31f461f402f

Contents?: true

Size: 1.09 KB

Versions: 17

Compression:

Stored size: 1.09 KB

Contents

namespace 'spree:migrations:migrate_user_addresses' do
  # This creates an entry in the user_addresses table for a user's currently
  # associated shipping and billing addresses.

  # This task should not need to be run more than once. But the de-dup behavior in
  # UserAddressBook should make it safe.
  # When the code (in the same PR) is deployed, each new order's addresses will be added
  # to the user's address book. This will catch up all the historical data.

  task up: :environment do
    Spree.user_class.find_each(batch_size: 500) do |user|
      ship_address = Spree::Address.find_by(id: user.ship_address_id)
      bill_address = Spree::Address.find_by(id: user.bill_address_id)

      current_addresses = [bill_address, ship_address].compact.uniq

      current_addresses.each do |address|
        # since ship_address is last, it will override bill_address as default when both are present
        user.save_in_address_book(address.attributes, true)
      end

      puts "Migrated addresses for user ##{user.id}"
    end
  end

  task down: :environment do
    Spree::UserAddress.delete_all
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
solidus_core-2.5.2 lib/tasks/migrations/migrate_user_addresses.rake
solidus_core-2.5.1 lib/tasks/migrations/migrate_user_addresses.rake
solidus_core-2.5.0 lib/tasks/migrations/migrate_user_addresses.rake
solidus_core-2.5.0.rc1 lib/tasks/migrations/migrate_user_addresses.rake
solidus_core-2.5.0.beta2 lib/tasks/migrations/migrate_user_addresses.rake
solidus_core-2.5.0.beta1 lib/tasks/migrations/migrate_user_addresses.rake
solidus_core-2.4.2 lib/tasks/migrations/migrate_user_addresses.rake
solidus_core-2.3.1 lib/tasks/migrations/migrate_user_addresses.rake
solidus_core-2.4.1 lib/tasks/migrations/migrate_user_addresses.rake
solidus_core-2.4.0 lib/tasks/migrations/migrate_user_addresses.rake
solidus_core-2.4.0.rc1 lib/tasks/migrations/migrate_user_addresses.rake
solidus_core-2.4.0.beta1 lib/tasks/migrations/migrate_user_addresses.rake
solidus_core-2.3.0 lib/tasks/migrations/migrate_user_addresses.rake
solidus_core-2.3.0.rc3 lib/tasks/migrations/migrate_user_addresses.rake
solidus_core-2.3.0.rc2 lib/tasks/migrations/migrate_user_addresses.rake
solidus_core-2.3.0.rc1 lib/tasks/migrations/migrate_user_addresses.rake
solidus_core-2.3.0.beta1 lib/tasks/migrations/migrate_user_addresses.rake