| 36943 |
amit |
1 |
-- Adds a `credited` flag to transaction.hdfc_payment so the manual add-money approval
|
|
|
2 |
-- (WalletController.addAmountToWallet) can tell a real auto-credit apart from a merely
|
|
|
3 |
-- captured row (VA missing/unmatched, introduced by r36927). Default 0 => every row starts
|
|
|
4 |
-- uncredited; the two backfills below set the historically-credited rows to 1.
|
|
|
5 |
--
|
|
|
6 |
-- Validated on hadb1 (2026-06-26): 100,029 hdfc_payment rows; 99,967 match an AUTOMATED_ADVANCE
|
|
|
7 |
-- credit by reference=id; of the 62 unmatched, 47 are old (2024-03..2024-10, pre-r36927, credited
|
|
|
8 |
-- by construction) and 15 are the new captured-but-uncredited rows (2026-06-25 16:23:49 onward,
|
|
|
9 |
-- all EMPTY / nwspic07092023 VAs). A UTR-in-description match rescued 0 extra rows, so reference=id
|
|
|
10 |
-- + the pre-r36927 date rule together are exact: only the 15 (growing) genuine captures stay 0.
|
|
|
11 |
|
|
|
12 |
ALTER TABLE transaction.hdfc_payment
|
|
|
13 |
ADD COLUMN credited TINYINT(1) NOT NULL DEFAULT 0;
|
|
|
14 |
|
|
|
15 |
-- Rule 1 ("if id is found"): a row is credited iff a wallet-history AUTOMATED_ADVANCE row
|
|
|
16 |
-- references it. The credit is written with reference = hdfc_payment.id
|
|
|
17 |
-- (HdfcPaymentController.addPayment -> walletService.addAmountToWallet(fofoId, stored.getId(), ...)
|
|
|
18 |
-- -> UserWalletHistory.setReference(referenceId)), so this join is exact.
|
|
|
19 |
UPDATE transaction.hdfc_payment hp
|
|
|
20 |
JOIN transaction.userwallethistory uwh
|
|
|
21 |
ON uwh.reference = hp.id
|
|
|
22 |
AND uwh.reference_type = 'AUTOMATED_ADVANCE'
|
|
|
23 |
SET hp.credited = 1;
|
|
|
24 |
|
|
|
25 |
-- Rule 2 ("older entries can be assumed true"): every row created before the r36927 deploy
|
|
|
26 |
-- (first capture-without-credit was 2026-06-25 16:23:49) is credited by construction -- pre-r36927
|
|
|
27 |
-- the hdfc_payment row was inserted ONLY after a successful credit. This covers the 47 old
|
|
|
28 |
-- unmatched rows (SIDBI sanctions / legacy reference schemes that left no AUTOMATED_ADVANCE match).
|
|
|
29 |
UPDATE transaction.hdfc_payment
|
|
|
30 |
SET credited = 1
|
|
|
31 |
WHERE create_timestamp < '2026-06-25 00:00:00';
|
|
|
32 |
|
|
|
33 |
-- After both: only post-r36927 captures with no wallet credit remain credited=0 -- i.e. the exact
|
|
|
34 |
-- set that is recoverable via the manual add-money (add_wallet_request) approval. Verify:
|
|
|
35 |
-- SELECT id, virtual_account, amount, create_timestamp
|
|
|
36 |
-- FROM transaction.hdfc_payment WHERE credited = 0 ORDER BY create_timestamp;
|