stakwork / sphinx-tribes

Backend for sphinx tribes and bounties. The bounty platform pays out in bitcoin. Sign up with Sphinx Chat, complete a bounty, and earn bitcoin! Go to our website for available bounties.
https://community.sphinx.chat/bounties
33 stars 60 forks source link

Monitoring: Negative balance DB #1663

Open tomsmith8 opened 5 months ago

tomsmith8 commented 5 months ago

Task

SQL qeury:

tomsmith8 commented 5 months ago

Stub: Monitoring where withdraw > deposits balance

fvalentiner commented 5 months ago

The SQL command to find workspaces with balances different than the sum of workspace transactions:

select ph.workspace_uuid, w.name, SUM(case when payment_type = 'withdraw' THEN amount -1 ELSE amount END) as amount, bb.total_budget, MAX(ph.updated) as last_transaction, MIN(ph.updated) as first_transaction from payment_histories as ph inner join workspaces as w on w.uuid = ph.workspace_uuid inner join bounty_budgets as bb on bb.workspace_uuid = ph.workspace_uuid WHERE status = true GROUP BY ph.workspace_uuid, w.name, bb.total_budget HAVING SUM(case when payment_type = 'withdraw' THEN amount -1 ELSE amount END) <> total_budget ORDER by amount DESC