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