Sha256: c0395c3ba06d2642c81fc2033b7499d4bc59e3304a3c846f839eed60ec34147a

Contents?: true

Size: 1.19 KB

Versions: 4

Compression:

Stored size: 1.19 KB

Contents

# This migration comes from spree (originally 20140530024945)
class MoveOrderTokenFromTokenizedPermission < ActiveRecord::Migration
  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

4 entries across 4 versions & 2 rubygems

Version Path
spree_weight_calculator-0.1.0 test/dummy/db/migrate/20160723192574_move_order_token_from_tokenized_permission.spree.rb
spree_order_reporting-0.0.3 spec/dummy/db/migrate/20160708163171_move_order_token_from_tokenized_permission.spree.rb
spree_order_reporting-0.0.2 spec/dummy/db/migrate/20160707103495_move_order_token_from_tokenized_permission.spree.rb
spree_order_reporting-0.0.1 spec/dummy/db/migrate/20160706112447_move_order_token_from_tokenized_permission.spree.rb