-- credit pools: compute credit is one pool ('compute', in standard-1 seconds) spent by every compute meter at its -- relative price, instead of a balance per compute meter. Only compute.runner (factor 1) ever held credit. INSERT INTO credit_balances (account_id, meter, balance, updated_at) SELECT account_id, 'compute', SUM(balance), MAX(updated_at) FROM credit_balances WHERE meter LIKE 'compute.%' GROUP BY account_id ON CONFLICT (account_id, meter) DO UPDATE SET balance = balance + excluded.balance, updated_at = excluded.updated_at; DELETE FROM credit_balances WHERE meter LIKE 'compute.%'; UPDATE credit_ledger SET meter = 'compute' WHERE meter LIKE 'compute.%';