Sha256: 2fef221c69027e5045b051044cda2b5750fa795271a7779e1b41af9ffdaf0dbc

Contents?: true

Size: 940 Bytes

Versions: 107

Compression:

Stored size: 940 Bytes

Contents

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

107 entries across 107 versions & 1 rubygems

Version Path
spree_core-4.0.9 db/migrate/20170330082155_add_indexes_to_spree_option_value_variant.rb
spree_core-4.1.15 db/migrate/20170330082155_add_indexes_to_spree_option_value_variant.rb
spree_core-4.2.7 db/migrate/20170330082155_add_indexes_to_spree_option_value_variant.rb
spree_core-4.3.3 db/migrate/20170330082155_add_indexes_to_spree_option_value_variant.rb
spree_core-4.2.6 db/migrate/20170330082155_add_indexes_to_spree_option_value_variant.rb
spree_core-4.3.2 db/migrate/20170330082155_add_indexes_to_spree_option_value_variant.rb
spree_core-4.3.1 db/migrate/20170330082155_add_indexes_to_spree_option_value_variant.rb
spree_core-4.3.0 db/migrate/20170330082155_add_indexes_to_spree_option_value_variant.rb
spree_core-4.3.0.rc3 db/migrate/20170330082155_add_indexes_to_spree_option_value_variant.rb
spree_core-4.3.0.rc2 db/migrate/20170330082155_add_indexes_to_spree_option_value_variant.rb
spree_core-4.3.0.rc1 db/migrate/20170330082155_add_indexes_to_spree_option_value_variant.rb
spree_core-4.2.5 db/migrate/20170330082155_add_indexes_to_spree_option_value_variant.rb
spree_core-4.1.14 db/migrate/20170330082155_add_indexes_to_spree_option_value_variant.rb
spree_core-4.0.8 db/migrate/20170330082155_add_indexes_to_spree_option_value_variant.rb
spree_core-4.2.4 db/migrate/20170330082155_add_indexes_to_spree_option_value_variant.rb
spree_core-3.7.14.1 db/migrate/20170330082155_add_indexes_to_spree_option_value_variant.rb
spree_core-4.2.3.1 db/migrate/20170330082155_add_indexes_to_spree_option_value_variant.rb
spree_core-4.1.13.1 db/migrate/20170330082155_add_indexes_to_spree_option_value_variant.rb
spree_core-4.0.7.1 db/migrate/20170330082155_add_indexes_to_spree_option_value_variant.rb
spree_core-4.2.3 db/migrate/20170330082155_add_indexes_to_spree_option_value_variant.rb