Sha256: 2b1ff659db81eaecb4468caff450af7dee54ab171d9b364721f42c641f92ed7c

Contents?: true

Size: 919 Bytes

Versions: 8

Compression:

Stored size: 919 Bytes

Contents

# This migration comes from spree (originally 20170331123832)
class AddIndexToShippingMethodZones < ActiveRecord::Migration[5.0]
  def change
    duplicates = Spree::ShippingMethodZone.group(:shipping_method_id, :zone_id).having('sum(1) > 1').size

    duplicates.each do |f|
      shipping_method_id, zone_id = f.first
      count = f.last - 1 # we want to leave one record
      zones = Spree::ShippingMethodZone.where(shipping_method_id: shipping_method_id, zone_id: zone_id).last(count)
      zones.map(&:destroy)
    end

    if index_exists? :spree_shipping_method_zones, [:shipping_method_id, :zone_id]
      remove_index :spree_shipping_method_zones, [:shipping_method_id, :zone_id]
      add_index :spree_shipping_method_zones, [:shipping_method_id, :zone_id], unique: true
    end

    add_index :spree_shipping_method_zones, :zone_id
    add_index :spree_shipping_method_zones, :shipping_method_id
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
spree_purchase_order-3.7.0 spec/dummy/db/migrate/20191113195962_add_index_to_shipping_method_zones.spree.rb
spree_billing_sisow-0.9.2 spec/dummy/db/migrate/20190729091903_add_index_to_shipping_method_zones.spree.rb
spree_billing_sisow-0.9.1 spec/dummy/db/migrate/20190729091903_add_index_to_shipping_method_zones.spree.rb
spree_purchase_order-3.6.0 spec/dummy/db/migrate/20180516191827_add_index_to_shipping_method_zones.spree.rb
spree_purchase_order-3.5.0 spec/dummy/db/migrate/20180516191827_add_index_to_shipping_method_zones.spree.rb
spree_purchase_order-3.5.0.rc1 spec/dummy/db/migrate/20180516191827_add_index_to_shipping_method_zones.spree.rb
spree_purchase_order-3.4.0 spec/dummy/db/migrate/20180516191827_add_index_to_shipping_method_zones.spree.rb
spree_purchase_order-3.3.0 spec/dummy/db/migrate/20180516191827_add_index_to_shipping_method_zones.spree.rb