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