Sha256: 94176b702abc8e27706099050e2a0ed08a2bdcf4b95a2b9655891e65b91002ea

Contents?: true

Size: 1002 Bytes

Versions: 8

Compression:

Stored size: 1002 Bytes

Contents

# This migration comes from spree (originally 20170330082155)
class AddIndexesToSpreeOptionValueVariant < ActiveRecord::Migration[5.0]
  def change
    duplicates = Spree::OptionValueVariant.group(:variant_id, :option_value_id).having('sum(1) > 1').size

    duplicates.each do |f|
      variant_id, option_value_id = f.first
      count = f.last - 1 # we want to leave one record
      ov = Spree::OptionValueVariant.where(variant_id: variant_id, option_value_id: option_value_id).last(count)
      ov.map(&:destroy)
    end

    if index_exists? :spree_option_value_variants, [:variant_id, :option_value_id], name: "index_option_values_variants_on_variant_id_and_option_value_id"
      remove_index :spree_option_value_variants, [:variant_id, :option_value_id]
      add_index :spree_option_value_variants, [:variant_id, :option_value_id], unique: true, name: "index_option_values_variants_on_variant_id_and_option_value_id"
    end

    add_index :spree_option_value_variants, :variant_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/20191113195952_add_indexes_to_spree_option_value_variant.spree.rb
spree_billing_sisow-0.9.2 spec/dummy/db/migrate/20190729091893_add_indexes_to_spree_option_value_variant.spree.rb
spree_billing_sisow-0.9.1 spec/dummy/db/migrate/20190729091893_add_indexes_to_spree_option_value_variant.spree.rb
spree_purchase_order-3.6.0 spec/dummy/db/migrate/20180516191817_add_indexes_to_spree_option_value_variant.spree.rb
spree_purchase_order-3.5.0 spec/dummy/db/migrate/20180516191817_add_indexes_to_spree_option_value_variant.spree.rb
spree_purchase_order-3.5.0.rc1 spec/dummy/db/migrate/20180516191817_add_indexes_to_spree_option_value_variant.spree.rb
spree_purchase_order-3.4.0 spec/dummy/db/migrate/20180516191817_add_indexes_to_spree_option_value_variant.spree.rb
spree_purchase_order-3.3.0 spec/dummy/db/migrate/20180516191817_add_indexes_to_spree_option_value_variant.spree.rb