Sha256: db66c6a8df47b7a826cab42741aaa054f7802dd8e5b071e782f5b43f52a79929
Contents?: true
Size: 708 Bytes
Versions: 8
Compression:
Stored size: 708 Bytes
Contents
# This migration comes from spree (originally 20170320145040) class AddUniqueIndexOnNumberToSpreeCustomerReturns < ActiveRecord::Migration[5.0] def change unless index_exists?(:spree_customer_returns, :number, unique: true) numbers = Spree::CustomerReturn.group(:number).having('sum(1) > 1').pluck(:number) returns = Spree::CustomerReturn.where(number: numbers) returns.find_each do |r| r.number = r.class.number_generator.method(:generate_permalink).call(r.class) r.save end remove_index :spree_customer_returns, :number if index_exists?(:spree_customer_returns, :number) add_index :spree_customer_returns, :number, unique: true end end end
Version data entries
8 entries across 8 versions & 2 rubygems