summaryrefslogtreecommitdiff
path: root/src/exchangedb/0002-history_requests.sql
diff options
context:
space:
mode:
Diffstat (limited to 'src/exchangedb/0002-history_requests.sql')
-rw-r--r--src/exchangedb/0002-history_requests.sql53
1 files changed, 44 insertions, 9 deletions
diff --git a/src/exchangedb/0002-history_requests.sql b/src/exchangedb/0002-history_requests.sql
index 853a435d4..0714e1bea 100644
--- a/src/exchangedb/0002-history_requests.sql
+++ b/src/exchangedb/0002-history_requests.sql
@@ -1,6 +1,6 @@
--
-- This file is part of TALER
--- Copyright (C) 2014--2022 Taler Systems SA
+-- Copyright (C) 2014--2023 Taler Systems SA
--
-- TALER is free software; you can redistribute it and/or modify it under the
-- terms of the GNU General Public License as published by the Free Software
@@ -16,13 +16,13 @@
CREATE FUNCTION create_table_history_requests(
- IN shard_suffix VARCHAR DEFAULT NULL
+ IN shard_suffix TEXT DEFAULT NULL
)
RETURNS VOID
LANGUAGE plpgsql
AS $$
DECLARE
- table_name VARCHAR DEFAULT 'history_requests';
+ table_name TEXT DEFAULT 'history_requests';
BEGIN
PERFORM create_partitioned_table(
'CREATE TABLE %I '
@@ -30,8 +30,7 @@ BEGIN
',reserve_pub BYTEA NOT NULL CHECK (LENGTH(reserve_pub)=32)'
',request_timestamp INT8 NOT NULL'
',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
- ',history_fee_val INT8 NOT NULL'
- ',history_fee_frac INT4 NOT NULL'
+ ',history_fee taler_amount NOT NULL'
',PRIMARY KEY (reserve_pub,request_timestamp)'
') %s ;'
,table_name
@@ -57,7 +56,7 @@ BEGIN
);
PERFORM comment_partitioned_column(
'History fee approved by the signature'
- ,'history_fee_val'
+ ,'history_fee'
,table_name
,shard_suffix
);
@@ -65,13 +64,13 @@ END $$;
CREATE FUNCTION constrain_table_history_requests(
- IN partition_suffix VARCHAR
+ IN partition_suffix TEXT
)
RETURNS void
LANGUAGE plpgsql
AS $$
DECLARE
- partition_name VARCHAR;
+ partition_name TEXT;
BEGIN
partition_name = concat_ws('_', 'history_requests', partition_suffix);
@@ -89,7 +88,7 @@ RETURNS VOID
LANGUAGE plpgsql
AS $$
DECLARE
- table_name VARCHAR DEFAULT 'history_requests';
+ table_name TEXT DEFAULT 'history_requests';
BEGIN
EXECUTE FORMAT (
'ALTER TABLE ' || table_name ||
@@ -100,6 +99,37 @@ BEGIN
END $$;
+CREATE OR REPLACE FUNCTION history_requests_insert_trigger()
+ RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+BEGIN
+ INSERT INTO reserve_history
+ (reserve_pub
+ ,table_name
+ ,serial_id)
+ VALUES
+ (NEW.reserve_pub
+ ,'history_requests'
+ ,NEW.history_request_serial_id);
+ RETURN NEW;
+END $$;
+COMMENT ON FUNCTION history_requests_insert_trigger()
+ IS 'Automatically generate reserve history entry.';
+
+
+CREATE FUNCTION master_table_history_requests()
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ CREATE TRIGGER history_requests_on_insert
+ AFTER INSERT
+ ON history_requests
+ FOR EACH ROW EXECUTE FUNCTION history_requests_insert_trigger();
+END $$;
+
+
INSERT INTO exchange_tables
(name
,version
@@ -121,4 +151,9 @@ INSERT INTO exchange_tables
,'exchange-0002'
,'foreign'
,TRUE
+ ,FALSE),
+ ('history_requests'
+ ,'exchange-0002'
+ ,'master'
+ ,TRUE
,FALSE);