Sha256: d0bcd838d05c87853186b56085d04768f25b9a204cc96406ec3bc8faed7be1e8

Contents?: true

Size: 601 Bytes

Versions: 14

Compression:

Stored size: 601 Bytes

Contents

# frozen_string_literal: true

class SetPromotionsWithAnyPolicyToAllIfPossible < ActiveRecord::Migration[5.2]
  def up
    Spree::Promotion.where(match_policy: :any).includes(:promotion_rules).all.find_each do |promotion|
      if promotion.promotion_rules.length <= 1
        promotion.update!(match_policy: :all)
      else
        raise StandardError, <<~MSG
          You have promotions with a match policy of any and more than one rule. Please
          run `bundle exec rake solidus:split_promotions_with_any_match_policy`.
        MSG
      end
    end
  end

  def down
    # No-Op
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
solidus_legacy_promotions-4.4.1 db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb
solidus_legacy_promotions-4.4.0 db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb
solidus_core-4.3.4 db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb
solidus_core-4.2.4 db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb
solidus_core-4.1.5 db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb
solidus_core-4.3.3 db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb
solidus_core-4.3.2 db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb
solidus_core-4.1.4 db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb
solidus_core-4.3.1 db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb
solidus_core-4.3.0 db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb
solidus_core-4.2.3 db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb
solidus_core-4.2.2 db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb
solidus_core-4.2.1 db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb
solidus_core-4.2.0 db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb