From e237727ba2e056026ba52b2928a0c4bb0c142f48 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 27 Feb 2021 14:52:34 +0000 Subject: [PATCH] Migrate payment fee adjustments to payment objects --- ...144926_migrate_payment_fees_to_payments.rb | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 db/migrate/20210227144926_migrate_payment_fees_to_payments.rb diff --git a/db/migrate/20210227144926_migrate_payment_fees_to_payments.rb b/db/migrate/20210227144926_migrate_payment_fees_to_payments.rb new file mode 100644 index 0000000000..5cd9c24ace --- /dev/null +++ b/db/migrate/20210227144926_migrate_payment_fees_to_payments.rb @@ -0,0 +1,22 @@ +class MigratePaymentFeesToPayments < ActiveRecord::Migration + class Spree::Adjustment < ActiveRecord::Base + belongs_to :originator, polymorphic: true + end + + def up + # Payment fee adjustments currently have the order as the `adjustable` and the payment as + # the `source`. Both `source` and `adjustable` will now be the payment. The `originator` is + # the payment method, and this is unchanged. + Spree::Adjustment.where(originator_type: 'Spree::PaymentMethod').update_all( + "adjustable_id = source_id, adjustable_type = 'Spree::Payment'" + ) + 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::PaymentMethod').update_all( + "adjustable_id = order_id, adjustable_type = 'Spree::Order'" + ) + end +end