Sha256: 1ab2a50d4da9c41b0ef88049ac6fe30841fb9b2ceea6ff121c05bcb5bb6832cf

Contents?: true

Size: 725 Bytes

Versions: 7

Compression:

Stored size: 725 Bytes

Contents

# This migration comes from spree (originally 20101026184808)
class MigrateCheckoutToOrders < ActiveRecord::Migration
  def up
    orders = select_all "SELECT * FROM orders"

    orders.each do |order|
      checkout = update_order(order)
      execute "DELETE FROM checkouts WHERE id = #{checkout['id']}" if checkout
    end
  end

  def down
  end

  private
    def update_order(order)
      checkout = select_one "SELECT * FROM checkouts WHERE order_id = #{order['id']}"

      if checkout
        execute "UPDATE orders SET email='#{checkout['email']}', bill_address_id = #{checkout['bill_address_id']}, ship_address_id = #{checkout['ship_address_id']} WHERE id = #{checkout['id']}"
      end
      checkout
    end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
spree_mercado_pago_payment_method-0.0.2 spec/dummy/db/migrate/20121121030204_migrate_checkout_to_orders.spree.rb
spree_mercado_pago_payment_method-0.1.1 spec/dummy/db/migrate/20121121030204_migrate_checkout_to_orders.spree.rb
spree_mercado_pago_payment_method-0.1.0 spec/dummy/db/migrate/20121121030204_migrate_checkout_to_orders.spree.rb
datashift_spree-0.3.0 spec/sandbox/db/migrate/20121023154423_migrate_checkout_to_orders.spree.rb
datashift_spree-0.2.1 spec/sandbox/db/migrate/20121015151216_migrate_checkout_to_orders.spree.rb
datashift_spree-0.2.0 spec/sandbox/db/migrate/20120925192784_migrate_checkout_to_orders.spree.rb
datashift_spree-0.1.0 spec/sandbox/db/migrate/20120918081515_migrate_checkout_to_orders.spree.rb