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.2.0.beta db/migrate/20170315152755_add_unique_index_on_number_to_spree_orders.rb
spree_core-4.1.9 db/migrate/20170315152755_add_unique_index_on_number_to_spree_orders.rb
spree_core-4.1.8 db/migrate/20170315152755_add_unique_index_on_number_to_spree_orders.rb
spree_core-4.1.7 db/migrate/20170315152755_add_unique_index_on_number_to_spree_orders.rb
spree_core-4.1.6 db/migrate/20170315152755_add_unique_index_on_number_to_spree_orders.rb
spree_core-4.1.5 db/migrate/20170315152755_add_unique_index_on_number_to_spree_orders.rb
spree_core-4.1.4 db/migrate/20170315152755_add_unique_index_on_number_to_spree_orders.rb
spree_core-4.1.3 db/migrate/20170315152755_add_unique_index_on_number_to_spree_orders.rb
spree_core-4.1.2 db/migrate/20170315152755_add_unique_index_on_number_to_spree_orders.rb
spree_core-4.1.1 db/migrate/20170315152755_add_unique_index_on_number_to_spree_orders.rb
spree_core-4.1.0 db/migrate/20170315152755_add_unique_index_on_number_to_spree_orders.rb
spree_core-4.1.0.rc3 db/migrate/20170315152755_add_unique_index_on_number_to_spree_orders.rb
spree_core-4.1.0.rc2 db/migrate/20170315152755_add_unique_index_on_number_to_spree_orders.rb
spree_core-4.1.0.rc1 db/migrate/20170315152755_add_unique_index_on_number_to_spree_orders.rb
spree_core-3.4.6 db/migrate/20170315152755_add_unique_index_on_number_to_spree_orders.rb
spree_core-3.7.10 db/migrate/20170315152755_add_unique_index_on_number_to_spree_orders.rb
spree_core-4.0.3 db/migrate/20170315152755_add_unique_index_on_number_to_spree_orders.rb
spree_core-3.7.9 db/migrate/20170315152755_add_unique_index_on_number_to_spree_orders.rb
spree_core-4.0.2 db/migrate/20170315152755_add_unique_index_on_number_to_spree_orders.rb
spree_core-3.7.8 db/migrate/20170315152755_add_unique_index_on_number_to_spree_orders.rb