diff options
Diffstat (limited to 'src/exchangedb/0002-reserves_open_deposits.sql')
-rw-r--r-- | src/exchangedb/0002-reserves_open_deposits.sql | 49 |
1 files changed, 42 insertions, 7 deletions
diff --git a/src/exchangedb/0002-reserves_open_deposits.sql b/src/exchangedb/0002-reserves_open_deposits.sql index 35605d360..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 @@ -15,13 +15,13 @@ -- CREATE FUNCTION create_table_reserves_open_deposits( - IN partition_suffix VARCHAR DEFAULT NULL + IN partition_suffix TEXT DEFAULT NULL ) RETURNS VOID LANGUAGE plpgsql AS $$ DECLARE - table_name VARCHAR default 'reserves_open_deposits'; + table_name TEXT default 'reserves_open_deposits'; BEGIN PERFORM create_partitioned_table( 'CREATE TABLE %I' @@ -30,8 +30,7 @@ BEGIN ',reserve_pub BYTEA NOT NULL CHECK (LENGTH(reserve_pub)=32)' ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)' ',coin_sig BYTEA NOT NULL CHECK (LENGTH(coin_sig)=64)' - ',contribution_val INT8 NOT NULL' - ',contribution_frac INT4 NOT NULL' + ',contribution taler_amount NOT NULL' ') %s ;' ,table_name ,'PARTITION BY HASH (coin_pub)' @@ -53,13 +52,13 @@ $$; CREATE FUNCTION constrain_table_reserves_open_deposits( - IN partition_suffix VARCHAR + IN partition_suffix TEXT ) RETURNS void LANGUAGE plpgsql AS $$ DECLARE - table_name VARCHAR default 'reserves_open_deposits'; + table_name TEXT default 'reserves_open_deposits'; BEGIN table_name = concat_ws('_', table_name, partition_suffix); EXECUTE FORMAT ( @@ -81,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 @@ -97,4 +127,9 @@ INSERT INTO exchange_tables ,'exchange-0002' ,'constrain' ,TRUE + ,FALSE), + ('reserves_open_deposits' + ,'exchange-0002' + ,'master' + ,TRUE ,FALSE); |