From 65bcf835529fc5f8535642492c6f34b71b26b8da Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Thu, 11 Feb 2021 12:29:11 +0000 Subject: [PATCH] Migrate shipping fee adjustments to shipments --- ...15125_migrate_shipment_fees_to_shipments.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 db/migrate/20210211115125_migrate_shipment_fees_to_shipments.rb diff --git a/db/migrate/20210211115125_migrate_shipment_fees_to_shipments.rb b/db/migrate/20210211115125_migrate_shipment_fees_to_shipments.rb new file mode 100644 index 0000000000..86cb5f3fee --- /dev/null +++ b/db/migrate/20210211115125_migrate_shipment_fees_to_shipments.rb @@ -0,0 +1,18 @@ +class MigrateShipmentFeesToShipments < ActiveRecord::Migration + def up + # Shipping fee adjustments currently have the order as the `adjustable` and the shipment as + # the `source`. Both `source` and `adjustable` will now be the shipment. The `originator` is + # the shipping method, and this is unchanged. + Spree::Adjustment.where(originator_type: 'Spree::ShippingMethod').update_all( + "adjustable_id = source_id, adjustable_type = 'Spree::Shipment'" + ) + end + + def down + # Just in case: reversing this migration requires setting the `adjustable` back to the order. + # The type is 'Spree::Order', and the order's id is still available on the `order_id` field. + Spree::Adjustment.where(originator_type: 'Spree::ShippingMethod').update_all( + "adjustable_id = order_id, adjustable_type = 'Spree::Order'" + ) + end +end