From 94a313d74b403f7afa130a999ab2171414f86a46 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 16 Sep 2023 14:04:36 +0200 Subject: create coin history table via triggers --- src/exchangedb/0002-reserves_open_deposits.sql | 38 +++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'src/exchangedb/0002-reserves_open_deposits.sql') diff --git a/src/exchangedb/0002-reserves_open_deposits.sql b/src/exchangedb/0002-reserves_open_deposits.sql index b1a292dd4..776859df8 100644 --- a/src/exchangedb/0002-reserves_open_deposits.sql +++ b/src/exchangedb/0002-reserves_open_deposits.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 @@ -80,6 +80,37 @@ END $$; +CREATE OR REPLACE FUNCTION reserves_open_deposits_insert_trigger() + RETURNS trigger + LANGUAGE plpgsql + AS $$ +BEGIN + INSERT INTO exchange.coin_history + (coin_pub + ,table_name + ,serial_id) + VALUES + (NEW.coin_pub + ,'reserves_open_deposits' + ,NEW.reserve_open_deposit_uuid); + RETURN NEW; +END $$; +COMMENT ON FUNCTION reserves_open_deposits_insert_trigger() + IS 'Automatically generate coin history entry.'; + + +CREATE FUNCTION master_table_reserves_open_deposits() +RETURNS VOID +LANGUAGE plpgsql +AS $$ +BEGIN + CREATE TRIGGER reserves_open_deposits_on_insert + AFTER INSERT + ON reserves_open_deposits + FOR EACH ROW EXECUTE FUNCTION reserves_open_deposits_insert_trigger(); +END $$; + + INSERT INTO exchange_tables (name ,version @@ -96,4 +127,9 @@ INSERT INTO exchange_tables ,'exchange-0002' ,'constrain' ,TRUE + ,FALSE), + ('reserves_open_deposits' + ,'exchange-0002' + ,'master' + ,TRUE ,FALSE); -- cgit v1.2.3