|
| 1 | +-- Update all payments witha "owed" status to "on_hold" for users that don't have a trolley_id |
| 2 | +-- and no trolley_recipient_payment_method set. |
| 3 | + |
| 4 | +UPDATE payment |
| 5 | +SET payment_status = 'ON_HOLD' |
| 6 | +WHERE winnings_id IN ( |
| 7 | + SELECT winnings.winning_id |
| 8 | + FROM winnings |
| 9 | + LEFT JOIN trolley_recipient ON winnings.winner_id = trolley_recipient.user_id |
| 10 | + LEFT JOIN trolley_recipient_payment_method ON trolley_recipient.id = trolley_recipient_payment_method.trolley_recipient_id |
| 11 | + WHERE payment.payment_status = 'OWED' AND ( |
| 12 | + trolley_recipient.trolley_id IS NULL OR |
| 13 | + trolley_recipient_payment_method.id IS NULL |
| 14 | + ) |
| 15 | +); |
| 16 | + |
| 17 | +-- To test & see the updated payments: |
| 18 | +-- |
| 19 | +-- SELECT payment.payment_id, |
| 20 | +-- payment.total_amount, |
| 21 | +-- payment.installment_number, |
| 22 | +-- payment.payment_method_id, |
| 23 | +-- payment.version, |
| 24 | +-- payment.payment_status, |
| 25 | +-- winnings.winner_id, |
| 26 | +-- trolley_recipient.trolley_id, |
| 27 | +-- trolley_recipient_payment_method.recipient_account_id |
| 28 | +-- FROM payment |
| 29 | +-- LEFT JOIN winnings ON payment.winnings_id = winnings.winning_id |
| 30 | +-- LEFT JOIN trolley_recipient ON winnings.winner_id = trolley_recipient.user_id |
| 31 | +-- LEFT JOIN trolley_recipient_payment_method ON trolley_recipient.id = trolley_recipient_payment_method.trolley_recipient_id |
| 32 | +-- WHERE payment.payment_status = 'OWED' |
| 33 | +-- AND trolley_recipient.trolley_id IS NULL |
| 34 | +-- AND trolley_recipient_payment_method.id IS NULL; |
0 commit comments