sphinx-tribes icon indicating copy to clipboard operation
sphinx-tribes copied to clipboard

Monitoring: Negative balance DB

Open tomsmith8 opened this issue 1 year ago • 2 comments

Task

  • Find all workspaces with negative balance
  • Nullify
  • Add function that checks balances in table for withdraw > deposit

SQL qeury:

tomsmith8 avatar May 21 '24 16:05 tomsmith8

Stub: Monitoring where withdraw > deposits balance

tomsmith8 avatar May 21 '24 16:05 tomsmith8

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

fvalentiner avatar May 21 '24 16:05 fvalentiner