Sha256: a34c7e42e4d122552c8cd85ec5b93851409beee9782ed3d66da5843adbedf83f

Contents?: true

Size: 806 Bytes

Versions: 3

Compression:

Stored size: 806 Bytes

Contents

# This migration comes from spree (originally 20140309023735)
class MigrateOldPreferences < ActiveRecord::Migration[4.2]
  def up
    if Spree::Calculator.respond_to?(:with_deleted)
      migrate_preferences(Spree::Calculator.with_deleted)
    else
      migrate_preferences(Spree::Calculator)
    end
    migrate_preferences(Spree::PaymentMethod)
    migrate_preferences(Spree::PromotionRule)
  end

  def down
  end

  private
  def migrate_preferences klass
    klass.reset_column_information
    klass.find_each do |record|
      store = Spree::Preferences::ScopedStore.new(record.class.name.underscore, record.id)
      record.defined_preferences.each do |key|
        value = store.fetch(key){}
        record.preferences[key] = value unless value.nil?
      end
      record.save!
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
spree_purchase_order-3.7.0 spec/dummy/db/migrate/20191113195841_migrate_old_preferences.spree.rb
spree_billing_sisow-0.9.2 spec/dummy/db/migrate/20190729091782_migrate_old_preferences.spree.rb
spree_billing_sisow-0.9.1 spec/dummy/db/migrate/20190729091782_migrate_old_preferences.spree.rb