Sha256: 21781ad322244b571ba66440aa53dab3c6efd6740b04ec1186b242ba3d094dd5

Contents?: true

Size: 1.46 KB

Versions: 22

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true
# This migration comes from spree (originally 20190106184413)

require 'solidus/migrations/promotions_with_code_handlers'

class RemoveCodeFromSpreePromotions < ActiveRecord::Migration[5.1]
  class Promotion < ActiveRecord::Base
    self.table_name = "spree_promotions"
    self.ignored_columns = %w(type)
  end

  def up
    promotions_with_code = Promotion.where.not(code: [nil, ''])

    if promotions_with_code.any?
      # You have some promotions with "code" field present! This is not good
      # since we are going to remove that column.
      #
      self.class.promotions_with_code_handler.new(self, promotions_with_code).call
    end

    remove_index :spree_promotions, name: :index_spree_promotions_on_code
    remove_column :spree_promotions, :code
  end

  def down
    add_column :spree_promotions, :code, :string
    add_index :spree_promotions, :code, name: :index_spree_promotions_on_code
  end

  def self.promotions_with_code_handler
    # We propose different approaches, just pick the one that you prefer or
    # write your custom one.
    #
    # The fist one (raising an exception) is the default but you can
    # comment/uncomment the one then better fits you needs or use a
    # custom class or callable object.
    #
    Solidus::Migrations::PromotionWithCodeHandlers::RaiseException
    # Solidus::Migrations::PromotionWithCodeHandlers::MoveToSpreePromotionCode
    # Solidus::Migrations::PromotionWithCodeHandlers::DoNothing
  end
end

Version data entries

22 entries across 22 versions & 8 rubygems

Version Path
solidus_i18n-2.2.0 spec/dummy/db/migrate/20210218213844_remove_code_from_spree_promotions.spree.rb
solidus_i18n-2.1.1 spec/dummy/db/migrate/20210218213844_remove_code_from_spree_promotions.spree.rb
solidus_auth_devise-2.5.4 spec/dummy/db/migrate/20211112052464_remove_code_from_spree_promotions.spree.rb
solidus_reports-1.0.0 spec/dummy/db/migrate/20211108200432_remove_code_from_spree_promotions.spree.rb
solidus_i18n-2.1.0 spec/dummy/db/migrate/20210218213844_remove_code_from_spree_promotions.spree.rb
solidus_auth_devise-2.5.3 spec/dummy/db/migrate/20210129115376_remove_code_from_spree_promotions.spree.rb
solidus_auth_devise-2.5.2 spec/dummy/db/migrate/20201006131567_remove_code_from_spree_promotions.spree.rb
solidus_auth_devise-2.5.1 spec/dummy/db/migrate/20201006131567_remove_code_from_spree_promotions.spree.rb
solidus_auth_devise-2.5.0 spec/dummy/db/migrate/20201006131567_remove_code_from_spree_promotions.spree.rb
solidus_reviews-1.4.1 spec/dummy/db/migrate/20200810122133_remove_code_from_spree_promotions.spree.rb
solidus_billing_address-0.0.7 spec/dummy/db/migrate/20191128105365_remove_code_from_spree_promotions.spree.rb
solidus_billing_address-0.0.6 spec/dummy/db/migrate/20191122155264_remove_code_from_spree_promotions.spree.rb
solidus_drip-0.1.0 spec/dummy/db/migrate/20191101230331_remove_code_from_spree_promotions.spree.rb
solidus_drip-0.0.1 spec/dummy/db/migrate/20191101230331_remove_code_from_spree_promotions.spree.rb
solidus_billing_address-0.0.5 spec/dummy/db/migrate/20191028084777_remove_code_from_spree_promotions.spree.rb
solidus_billing_address-0.0.4 spec/dummy/db/migrate/20190926134968_remove_code_from_spree_promotions.spree.rb
solidus_billing_address-0.0.3 spec/dummy/db/migrate/20190924075662_remove_code_from_spree_promotions.spree.rb
solidus_billing_address-0.0.2 spec/dummy/db/migrate/20190920154652_remove_code_from_spree_promotions.spree.rb
solidus_billing_address-0.0.1 spec/dummy/db/migrate/20190823131028_remove_code_from_spree_promotions.spree.rb
solidus_bank_transfer-0.1.0 spec/dummy/db/migrate/20190822093462_remove_code_from_spree_promotions.spree.rb