Skip to content

PM-1206 - reset payment status #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
-- Update all payments witha "owed" status to "on_hold" for users that don't have a trolley_id
-- and no trolley_recipient_payment_method set.

UPDATE payment
SET payment_status = 'ON_HOLD'
WHERE winnings_id IN (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium
performance
The subquery in the WHERE clause could potentially lead to performance issues if the winnings table is large. Consider using an EXISTS clause instead of IN to improve performance by stopping at the first match.

SELECT winnings.winning_id
FROM winnings
LEFT JOIN trolley_recipient ON winnings.winner_id = trolley_recipient.user_id
LEFT JOIN trolley_recipient_payment_method ON trolley_recipient.id = trolley_recipient_payment_method.trolley_recipient_id
WHERE payment.payment_status = 'OWED' AND (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high
correctness
Ensure that the payment table is correctly joined with the winnings table. The current query assumes that winnings_id in the payment table directly corresponds to winning_id in the winnings table, which might not be the case if there are any discrepancies or missing foreign key constraints.

trolley_recipient.trolley_id IS NULL OR
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please remove this?
Sorry, had to mention this in AC, but realized we could have trolley_id records pre-created for members when we import offline data. So we want to target members without trolley_recipient_payment_method set.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cleared in Slack.

trolley_recipient_payment_method.id IS NULL
)
);

-- To test & see the updated payments:
--
-- SELECT payment.payment_id,
-- payment.total_amount,
-- payment.installment_number,
-- payment.payment_method_id,
-- payment.version,
-- payment.payment_status,
-- winnings.winner_id,
-- trolley_recipient.trolley_id,
-- trolley_recipient_payment_method.recipient_account_id
-- FROM payment
-- LEFT JOIN winnings ON payment.winnings_id = winnings.winning_id
-- LEFT JOIN trolley_recipient ON winnings.winner_id = trolley_recipient.user_id
-- LEFT JOIN trolley_recipient_payment_method ON trolley_recipient.id = trolley_recipient_payment_method.trolley_recipient_id
-- WHERE payment.payment_status = 'OWED'
-- AND trolley_recipient.trolley_id IS NULL
-- AND trolley_recipient_payment_method.id IS NULL;