summaryrefslogtreecommitdiff
path: root/src/exchangedb/0002-refunds.sql
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2023-09-16 14:04:36 +0200
committerChristian Grothoff <christian@grothoff.org>2023-09-16 14:04:36 +0200
commit94a313d74b403f7afa130a999ab2171414f86a46 (patch)
tree74a5b4cdaaf84d93e89a56372bbac51673d1bbb6 /src/exchangedb/0002-refunds.sql
parent82f353ce4e3c19f01fcf078b76ae613550673c75 (diff)
downloadexchange-94a313d74b403f7afa130a999ab2171414f86a46.tar.gz
exchange-94a313d74b403f7afa130a999ab2171414f86a46.tar.bz2
exchange-94a313d74b403f7afa130a999ab2171414f86a46.zip
create coin history table via triggers
Diffstat (limited to 'src/exchangedb/0002-refunds.sql')
-rw-r--r--src/exchangedb/0002-refunds.sql38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/exchangedb/0002-refunds.sql b/src/exchangedb/0002-refunds.sql
index 6eae5532b..2a40bc192 100644
--- a/src/exchangedb/0002-refunds.sql
+++ b/src/exchangedb/0002-refunds.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
@@ -102,6 +102,37 @@ END
$$;
+CREATE OR REPLACE FUNCTION refunds_insert_trigger()
+ RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+BEGIN
+ INSERT INTO exchange.coin_history
+ (coin_pub
+ ,table_name
+ ,serial_id)
+ VALUES
+ (NEW.coin_pub
+ ,'refunds'
+ ,NEW.refund_serial_id);
+ RETURN NEW;
+END $$;
+COMMENT ON FUNCTION refunds_insert_trigger()
+ IS 'Automatically generate coin history entry.';
+
+
+CREATE FUNCTION master_table_refunds()
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ CREATE TRIGGER refunds_on_insert
+ AFTER INSERT
+ ON refunds
+ FOR EACH ROW EXECUTE FUNCTION refunds_insert_trigger();
+END $$;
+
+
INSERT INTO exchange_tables
(name
,version
@@ -123,4 +154,9 @@ INSERT INTO exchange_tables
,'exchange-0002'
,'foreign'
,TRUE
+ ,FALSE),
+ ('refunds'
+ ,'exchange-0002'
+ ,'master'
+ ,TRUE
,FALSE);