Sha256: 198b7ae753ac10f674cc294445c0834867b7010704e4ff7efbf37bfdd03bb005

Contents?: true

Size: 721 Bytes

Versions: 107

Compression:

Stored size: 721 Bytes

Contents

class AddUniqueIndexOnNumberToSpreePayments < ActiveRecord::Migration[5.0]
  def change
    unless index_exists?(:spree_payments, :number, unique: true)
      # default scope in Spree::Payment disturbs Postgres, hence `unscoped` is needed.
      numbers = Spree::Payment.unscoped.group(:number).having('sum(1) > 1').pluck(:number)
      payments = Spree::Payment.where(number: numbers)

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

      remove_index :spree_payments, :number if index_exists?(:spree_payments, :number)
      add_index :spree_payments, :number, unique: true
    end
  end
end

Version data entries

107 entries across 107 versions & 1 rubygems

Version Path
spree_core-4.0.9 db/migrate/20170320134043_add_unique_index_on_number_to_spree_payments.rb
spree_core-4.1.15 db/migrate/20170320134043_add_unique_index_on_number_to_spree_payments.rb
spree_core-4.2.7 db/migrate/20170320134043_add_unique_index_on_number_to_spree_payments.rb
spree_core-4.3.3 db/migrate/20170320134043_add_unique_index_on_number_to_spree_payments.rb
spree_core-4.2.6 db/migrate/20170320134043_add_unique_index_on_number_to_spree_payments.rb
spree_core-4.3.2 db/migrate/20170320134043_add_unique_index_on_number_to_spree_payments.rb
spree_core-4.3.1 db/migrate/20170320134043_add_unique_index_on_number_to_spree_payments.rb
spree_core-4.3.0 db/migrate/20170320134043_add_unique_index_on_number_to_spree_payments.rb
spree_core-4.3.0.rc3 db/migrate/20170320134043_add_unique_index_on_number_to_spree_payments.rb
spree_core-4.3.0.rc2 db/migrate/20170320134043_add_unique_index_on_number_to_spree_payments.rb
spree_core-4.3.0.rc1 db/migrate/20170320134043_add_unique_index_on_number_to_spree_payments.rb
spree_core-4.2.5 db/migrate/20170320134043_add_unique_index_on_number_to_spree_payments.rb
spree_core-4.1.14 db/migrate/20170320134043_add_unique_index_on_number_to_spree_payments.rb
spree_core-4.0.8 db/migrate/20170320134043_add_unique_index_on_number_to_spree_payments.rb
spree_core-4.2.4 db/migrate/20170320134043_add_unique_index_on_number_to_spree_payments.rb
spree_core-3.7.14.1 db/migrate/20170320134043_add_unique_index_on_number_to_spree_payments.rb
spree_core-4.2.3.1 db/migrate/20170320134043_add_unique_index_on_number_to_spree_payments.rb
spree_core-4.1.13.1 db/migrate/20170320134043_add_unique_index_on_number_to_spree_payments.rb
spree_core-4.0.7.1 db/migrate/20170320134043_add_unique_index_on_number_to_spree_payments.rb
spree_core-4.2.3 db/migrate/20170320134043_add_unique_index_on_number_to_spree_payments.rb