Sha256: 18f8f5a14ee888e47e35535bc91905ca75f73b047764ae5f0fe44c640c9c8c0a

Contents?: true

Size: 659 Bytes

Versions: 8

Compression:

Stored size: 659 Bytes

Contents

# This migration comes from spree (originally 20170315152755)
class AddUniqueIndexOnNumberToSpreeOrders < ActiveRecord::Migration[5.0]
  def change
    unless index_exists?(:spree_orders, :number, unique: true)
      numbers = Spree::Order.group(:number).having('sum(1) > 1').pluck(:number)
      orders = Spree::Order.where(number: numbers)

      orders.find_each do |order|
        order.number = order.class.number_generator.method(:generate_permalink).call(order.class)
        order.save
      end

      remove_index :spree_orders, :number if index_exists?(:spree_orders, :number)
      add_index :spree_orders, :number, unique: true
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
spree_purchase_order-3.7.0 spec/dummy/db/migrate/20191113195942_add_unique_index_on_number_to_spree_orders.spree.rb
spree_billing_sisow-0.9.2 spec/dummy/db/migrate/20190729091883_add_unique_index_on_number_to_spree_orders.spree.rb
spree_billing_sisow-0.9.1 spec/dummy/db/migrate/20190729091883_add_unique_index_on_number_to_spree_orders.spree.rb
spree_purchase_order-3.6.0 spec/dummy/db/migrate/20180516191807_add_unique_index_on_number_to_spree_orders.spree.rb
spree_purchase_order-3.5.0 spec/dummy/db/migrate/20180516191807_add_unique_index_on_number_to_spree_orders.spree.rb
spree_purchase_order-3.5.0.rc1 spec/dummy/db/migrate/20180516191807_add_unique_index_on_number_to_spree_orders.spree.rb
spree_purchase_order-3.4.0 spec/dummy/db/migrate/20180516191807_add_unique_index_on_number_to_spree_orders.spree.rb
spree_purchase_order-3.3.0 spec/dummy/db/migrate/20180516191807_add_unique_index_on_number_to_spree_orders.spree.rb