Sha256: daa6d2fb4e66e894d3a96a4df50218e6b7b19c8511d2c022472b0bb09bd32c15

Contents?: true

Size: 817 Bytes

Versions: 8

Compression:

Stored size: 817 Bytes

Contents

# This migration comes from spree (originally 20170320142750)
class AddUniqueIndexOnNumberToSpreeReturnAuthorizations < ActiveRecord::Migration[5.0]
  def change
    unless index_exists?(:spree_return_authorizations, :number, unique: true)
      numbers = Spree::ReturnAuthorization.group(:number).having('sum(1) > 1').pluck(:number)
      authorizations = Spree::ReturnAuthorization.where(number: numbers)

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

      remove_index :spree_return_authorizations, :number if index_exists?(:spree_return_authorizations, :number)
      add_index :spree_return_authorizations, :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/20191113195946_add_unique_index_on_number_to_spree_return_authorizations.spree.rb
spree_billing_sisow-0.9.2 spec/dummy/db/migrate/20190729091887_add_unique_index_on_number_to_spree_return_authorizations.spree.rb
spree_billing_sisow-0.9.1 spec/dummy/db/migrate/20190729091887_add_unique_index_on_number_to_spree_return_authorizations.spree.rb
spree_purchase_order-3.6.0 spec/dummy/db/migrate/20180516191811_add_unique_index_on_number_to_spree_return_authorizations.spree.rb
spree_purchase_order-3.5.0 spec/dummy/db/migrate/20180516191811_add_unique_index_on_number_to_spree_return_authorizations.spree.rb
spree_purchase_order-3.5.0.rc1 spec/dummy/db/migrate/20180516191811_add_unique_index_on_number_to_spree_return_authorizations.spree.rb
spree_purchase_order-3.4.0 spec/dummy/db/migrate/20180516191811_add_unique_index_on_number_to_spree_return_authorizations.spree.rb
spree_purchase_order-3.3.0 spec/dummy/db/migrate/20180516191811_add_unique_index_on_number_to_spree_return_authorizations.spree.rb