Sha256: 3b5c6ef17fcdad98a8811004d4f6cd4a0421bdb865a58cb3e0b2bf18805ea21e

Contents?: true

Size: 739 Bytes

Versions: 8

Compression:

Stored size: 739 Bytes

Contents

# This migration comes from spree (originally 20170316154338)
class AddUniqueIndexOnNumberToSpreeStockTransfer < ActiveRecord::Migration[5.0]
  def change
    unless index_exists?(:spree_stock_transfers, :number, unique: true)
      numbers = Spree::StockTransfer.group(:number).having('sum(1) > 1').pluck(:number)
      transfers = Spree::StockTransfer.where(number: numbers)

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

      remove_index :spree_stock_transfers, :number if index_exists?(:spree_stock_transfers, :number)
      add_index :spree_stock_transfers, :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/20191113195943_add_unique_index_on_number_to_spree_stock_transfer.spree.rb
spree_billing_sisow-0.9.2 spec/dummy/db/migrate/20190729091884_add_unique_index_on_number_to_spree_stock_transfer.spree.rb
spree_billing_sisow-0.9.1 spec/dummy/db/migrate/20190729091884_add_unique_index_on_number_to_spree_stock_transfer.spree.rb
spree_purchase_order-3.6.0 spec/dummy/db/migrate/20180516191808_add_unique_index_on_number_to_spree_stock_transfer.spree.rb
spree_purchase_order-3.5.0 spec/dummy/db/migrate/20180516191808_add_unique_index_on_number_to_spree_stock_transfer.spree.rb
spree_purchase_order-3.5.0.rc1 spec/dummy/db/migrate/20180516191808_add_unique_index_on_number_to_spree_stock_transfer.spree.rb
spree_purchase_order-3.4.0 spec/dummy/db/migrate/20180516191808_add_unique_index_on_number_to_spree_stock_transfer.spree.rb
spree_purchase_order-3.3.0 spec/dummy/db/migrate/20180516191808_add_unique_index_on_number_to_spree_stock_transfer.spree.rb