Sha256: ff96b0191da9c16248aaeaa44aaa1a6f9411a91f479d24d022d9a806b3bc4d89

Contents?: true

Size: 951 Bytes

Versions: 8

Compression:

Stored size: 951 Bytes

Contents

# This migration comes from spree (originally 20170329113917)
class AddIndexOnPrototypeToSpreeOptionTypePrototype < ActiveRecord::Migration[5.0]
  def change
    duplicates = Spree::OptionTypePrototype.group(:prototype_id, :option_type_id).having('sum(1) > 1').size

    duplicates.each do |f|
      prototype_id, option_type_id = f.first
      count = f.last - 1 # we want to leave one record
      otp = Spree::OptionTypePrototype.where(prototype_id: prototype_id, option_type_id: option_type_id).last(count)
      otp.map(&:destroy)
    end

    if index_exists? :spree_option_type_prototypes, [:prototype_id, :option_type_id]
      remove_index :spree_option_type_prototypes, [:prototype_id, :option_type_id]
      add_index :spree_option_type_prototypes, [:prototype_id, :option_type_id], unique: true, name: 'spree_option_type_prototypes_prototype_id_option_type_id'
    end

    add_index :spree_option_type_prototypes, :prototype_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/20191113195951_add_index_on_prototype_to_spree_option_type_prototype.spree.rb
spree_billing_sisow-0.9.2 spec/dummy/db/migrate/20190729091892_add_index_on_prototype_to_spree_option_type_prototype.spree.rb
spree_billing_sisow-0.9.1 spec/dummy/db/migrate/20190729091892_add_index_on_prototype_to_spree_option_type_prototype.spree.rb
spree_purchase_order-3.6.0 spec/dummy/db/migrate/20180516191816_add_index_on_prototype_to_spree_option_type_prototype.spree.rb
spree_purchase_order-3.5.0 spec/dummy/db/migrate/20180516191816_add_index_on_prototype_to_spree_option_type_prototype.spree.rb
spree_purchase_order-3.5.0.rc1 spec/dummy/db/migrate/20180516191816_add_index_on_prototype_to_spree_option_type_prototype.spree.rb
spree_purchase_order-3.4.0 spec/dummy/db/migrate/20180516191816_add_index_on_prototype_to_spree_option_type_prototype.spree.rb
spree_purchase_order-3.3.0 spec/dummy/db/migrate/20180516191816_add_index_on_prototype_to_spree_option_type_prototype.spree.rb