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