chezbob / chezbob-legacy

The main repo for Chez Bob at UCSD.
0 stars 0 forks source link

Balance inconsistencies #65

Closed jdeblasio closed 8 years ago

jdeblasio commented 8 years ago

So here's something bad.

Go run this query:

SELECT
    u.userid,
    username,
    nickname,
    sum(xactvalue) AS trans_bal,
    balance AS user_bal,
    (sum(xactvalue) - balance) AS bal_diff,
    greatest(last_deposit_time, last_purchase_time)::date AS last_active,
    disabled,
    created_time::date
FROM transactions AS t
    inner join users AS u ON u.userid = t.userid
GROUP BY t.userid, u.userid
HAVING sum(xactvalue) != balance
ORDER BY bal_diff DESC;

For all of those users, their balance isn't equal to the sum of their transactions, which should never happen. In all of the remaining cases, the balance calculated from the transaction table is larger than the balance from the user table. This was the common case.

There were 27 cases where the balances were unequal in the other direction, but I added artificial 'ADD' transactions to adjust those, and the differences were all pretty small (<$5).

We have several people where their transaction logs imply that their balance should be more than $20 higher than the user table lists it as. If we could:

  1. Hunt down why this is happening, and fix it, and
  2. Figure out a strategy for all of these folks.

This is a bounty-eligible bug.

jdeblasio commented 8 years ago

I've adjusted everyone's balances (according to a magical, subjective heuristic in my head). We'll check back in periodically to see if this happens again. If it does, we can go from there. Closing this ticket until then.