Sha256: 485dc6a07b9e40c4593acd7f1deec9d848a0e9ea24f1ebd7d8ff0df08ca65eb7

Contents?: true

Size: 1.19 KB

Versions: 9

Compression:

Stored size: 1.19 KB

Contents

# This migration comes from spree (originally 20140530024945)
class MoveOrderTokenFromTokenizedPermission < ActiveRecord::Migration[4.2]
  class Spree::TokenizedPermission < Spree::Base
    belongs_to :permissable, polymorphic: true
  end

  def up
    case Spree::Order.connection.adapter_name
    when 'SQLite'
      Spree::Order.has_one :tokenized_permission, as: :permissable
      Spree::Order.includes(:tokenized_permission).each do |o|
        o.update_column :guest_token, o.tokenized_permission.token
      end
    when 'Mysql2', 'MySQL'
      execute "UPDATE spree_orders, spree_tokenized_permissions
               SET spree_orders.guest_token = spree_tokenized_permissions.token
               WHERE spree_tokenized_permissions.permissable_id = spree_orders.id
                  AND spree_tokenized_permissions.permissable_type = 'Spree::Order'"
    else
      execute "UPDATE spree_orders
               SET guest_token = spree_tokenized_permissions.token
               FROM spree_tokenized_permissions
               WHERE spree_tokenized_permissions.permissable_id = spree_orders.id
                  AND spree_tokenized_permissions.permissable_type = 'Spree::Order'"
    end
  end

  def down
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
spree_purchase_order-3.7.0 spec/dummy/db/migrate/20191113195852_move_order_token_from_tokenized_permission.spree.rb
spree_billing_sisow-0.9.2 spec/dummy/db/migrate/20190729091793_move_order_token_from_tokenized_permission.spree.rb
spree_billing_sisow-0.9.1 spec/dummy/db/migrate/20190729091793_move_order_token_from_tokenized_permission.spree.rb
spree_purchase_order-3.6.0 spec/dummy/db/migrate/20180516181981_move_order_token_from_tokenized_permission.spree.rb
spree_purchase_order-3.5.0 spec/dummy/db/migrate/20180516181981_move_order_token_from_tokenized_permission.spree.rb
spree_purchase_order-3.5.0.rc1 spec/dummy/db/migrate/20180516181981_move_order_token_from_tokenized_permission.spree.rb
spree_purchase_order-3.4.0 spec/dummy/db/migrate/20180516181981_move_order_token_from_tokenized_permission.spree.rb
spree_purchase_order-3.3.0 spec/dummy/db/migrate/20180516181981_move_order_token_from_tokenized_permission.spree.rb
spree_purchase_order-3.2.0 spec/dummy/db/migrate/20180516181981_move_order_token_from_tokenized_permission.spree.rb