Sha256: 032173ae1859c7a96b1f8278ac86ad110f52944b65060aec595de01b96f9c623

Contents?: true

Size: 597 Bytes

Versions: 107

Compression:

Stored size: 597 Bytes

Contents

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

107 entries across 107 versions & 1 rubygems

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