Sha256: 24c5564d8de2858f400cf8fa408d554b17e79f697f925daf8dafb5ad05a21016

Contents?: true

Size: 969 Bytes

Versions: 8

Compression:

Stored size: 969 Bytes

Contents

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

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

    if index_exists? :spree_property_prototypes, [:prototype_id, :property_id]
      remove_index :spree_property_prototypes, [:prototype_id, :property_id]
      add_index :spree_property_prototypes, [:prototype_id, :property_id], unique: true, name: 'index_property_prototypes_on_prototype_id_and_property_id'
    end

    add_index :spree_property_prototypes, :prototype_id
    add_index :spree_property_prototypes, :property_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/20191113195954_add_indexes_for_property_prototype.spree.rb
spree_billing_sisow-0.9.2 spec/dummy/db/migrate/20190729091895_add_indexes_for_property_prototype.spree.rb
spree_billing_sisow-0.9.1 spec/dummy/db/migrate/20190729091895_add_indexes_for_property_prototype.spree.rb
spree_purchase_order-3.6.0 spec/dummy/db/migrate/20180516191819_add_indexes_for_property_prototype.spree.rb
spree_purchase_order-3.5.0 spec/dummy/db/migrate/20180516191819_add_indexes_for_property_prototype.spree.rb
spree_purchase_order-3.5.0.rc1 spec/dummy/db/migrate/20180516191819_add_indexes_for_property_prototype.spree.rb
spree_purchase_order-3.4.0 spec/dummy/db/migrate/20180516191819_add_indexes_for_property_prototype.spree.rb
spree_purchase_order-3.3.0 spec/dummy/db/migrate/20180516191819_add_indexes_for_property_prototype.spree.rb