commit 8f237b69fc4f4054e8f2697858f2af589b2da2dc
parent 0fafe97aec9cf4b13274d12ea03e09d798653ad3
Author: MS <ms@taler.net>
Date: Wed, 4 Oct 2023 16:34:54 +0200
Defining stats table.
Diffstat:
1 file changed, 27 insertions(+), 0 deletions(-)
diff --git a/database-versioning/libeufin-bank-0001.sql b/database-versioning/libeufin-bank-0001.sql
@@ -47,6 +47,9 @@ CREATE TYPE subscriber_key_state_enum
CREATE TYPE subscriber_state_enum
AS ENUM ('new', 'confirmed');
+CREATE TYPE stat_timeframe_enum
+ AS ENUM ('hour', 'day', 'month', 'year', '10years');
+
-- FIXME: comments on types (see exchange for example)!
-- start of: bank accounts
@@ -392,4 +395,28 @@ COMMENT ON COLUMN taler_withdrawal_operations.confirmation_done
IS 'Signals whether the payment to the exchange took place';
-- end of: Taler integration
+
+CREATE TABLE IF NOT EXISTS regional_stats (
+ regional_stats_id BIGINT GENERATED BY DEFAULT AS IDENTITY
+ ,cashin_count BIGINT NOT NULL
+ ,cashin_volume_in_fiat taler_amount NOT NULL
+ ,cashout_count BIGINT NOT NULL
+ ,cashout_volume_in_fiat taler_amount NOT NULL
+ ,internal_taler_payments_count BIGINT NOT NULL
+ ,internal_taler_payments_volume taler_amount NOT NULL
+ ,taler_exchange_balance taler_amount NOT NULL -- FIXME: this can't be accurate, as balance changes continuously.
+ ,timeframe stat_timeframe_enum NOT NULL
+);
+
+COMMENT ON TABLE regional_stats IS
+ 'Stores statistics about the regional currency usage. At any given time, this table stores at most: 23 hour rows, 29 day rows, 11 month rows, 9 year rows, and any number of 10year rows';
+COMMENT ON COLUMN regional_stats.cashin_count IS 'how many cashin operations took place in the timeframe';
+COMMENT ON COLUMN regional_stats.cashin_volume_in_fiat IS 'how much fiat currency was cashed in in the timeframe';
+COMMENT ON COLUMN regional_stats.cashout_count IS 'how many cashout operations took place in the timeframe';
+COMMENT ON COLUMN regional_stats.cashout_volume_in_fiat IS 'how much fiat currency was payed by the bank to customers in the timeframe';
+COMMENT ON COLUMN regional_stats.internal_taler_payments_count IS 'how many internal payments were made by a Taler exchange';
+COMMENT ON COLUMN regional_stats.internal_taler_payments_volume IS 'how much internal currency was paid by a Taler exchange';
+COMMENT ON COLUMN regional_stats.taler_exchange_balance IS 'balance of the Taler exchange at the given timeframe'; -- FIXME: see FIXME above.
+COMMENT ON COLUMN regional_stats.timeframe IS 'particular timeframe that this row accounts for';
+
COMMIT;