diff --git a/db/migrate/20241220095049_backfill_payable_payment_status.rb b/db/migrate/20241220095049_backfill_payable_payment_status.rb new file mode 100644 index 000000000000..d52ea35f812a --- /dev/null +++ b/db/migrate/20241220095049_backfill_payable_payment_status.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class BackfillPayablePaymentStatus < ActiveRecord::Migration[7.1] + def change + provider_types = PaymentProviders::BaseProvider.distinct.pluck(:type) + provider_types.each do |provider_type| + provider_class = provider_type.constantize + + payments = Payment.joins(:payment_provider) + .where(payment_providers: {type: provider_type}, status: provider_class::PENDING_STATUSES) + payments.update_all(payable_payment_status: :pending) + + payments = Payment.joins(:payment_provider) + .where(payment_providers: {type: provider_type}, status: provider_class::SUCCESS_STATUSES) + payments.update_all(payable_payment_status: :succeeded) + + payments = Payment.joins(:payment_provider) + .where(payment_providers: {type: provider_type}, status: provider_class::FAILED_STATUSES) + payments.update_all(payable_payment_status: :failed) + end + end +end