From a51517f64c83c23545ebd8a935baa311f0de635a Mon Sep 17 00:00:00 2001
From: Christian Grothoff <christian@grothoff.org>
Date: Wed, 2 Nov 2022 17:51:42 +0100
Subject: -implement missing functions

---
 src/auditordb/auditor-0001.sql | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

(limited to 'src/auditordb/auditor-0001.sql')

diff --git a/src/auditordb/auditor-0001.sql b/src/auditordb/auditor-0001.sql
index 7bd5531e8..a19655d42 100644
--- a/src/auditordb/auditor-0001.sql
+++ b/src/auditordb/auditor-0001.sql
@@ -170,8 +170,8 @@ CREATE INDEX IF NOT EXISTS auditor_reserves_by_reserve_pub
 CREATE TABLE IF NOT EXISTS auditor_purses
   (purse_pub BYTEA NOT NULL CHECK(LENGTH(purse_pub)=32)
   ,master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
-  ,balance_val INT8 NOT NULL
-  ,balance_frac INT4 NOT NULL
+  ,balance_val INT8 NOT NULL DEFAULT(0)
+  ,balance_frac INT4 NOT NULL DEFAULT(0)
   ,target_val INT8 NOT NULL
   ,target_frac INT4 NOT NULL
   ,expiration_date INT8 NOT NULL
@@ -185,6 +185,20 @@ CREATE INDEX IF NOT EXISTS auditor_purses_by_purse_pub
   (purse_pub);
 
 
+CREATE TABLE IF NOT EXISTS auditor_purse_summary
+  (master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
+  ,balance_val INT8 NOT NULL
+  ,balance_frac INT4 NOT NULL
+  ,open_purses INT8 NOT NULL
+  );
+COMMENT ON TABLE auditor_purse_summary
+  IS 'sum of the balances in open purses';
+
+CREATE INDEX IF NOT EXISTS auditor_purses_by_purse_pub
+  ON auditor_purses
+  (purse_pub);
+
+
 CREATE TABLE IF NOT EXISTS auditor_reserve_balance
   (master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
   ,reserve_balance_val INT8 NOT NULL
-- 
cgit v1.2.3

