summaryrefslogtreecommitdiff
path: root/src/exchangedb/0002-purse_deposits.sql
diff options
context:
space:
mode:
Diffstat (limited to 'src/exchangedb/0002-purse_deposits.sql')
-rw-r--r--src/exchangedb/0002-purse_deposits.sql58
1 files changed, 44 insertions, 14 deletions
diff --git a/src/exchangedb/0002-purse_deposits.sql b/src/exchangedb/0002-purse_deposits.sql
index 9452f4344..6a07c4b62 100644
--- a/src/exchangedb/0002-purse_deposits.sql
+++ b/src/exchangedb/0002-purse_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_purse_deposits(
- IN partition_suffix VARCHAR DEFAULT NULL
+ IN partition_suffix TEXT DEFAULT NULL
)
RETURNS VOID
LANGUAGE plpgsql
AS $$
DECLARE
- table_name VARCHAR DEFAULT 'purse_deposits';
+ table_name TEXT DEFAULT 'purse_deposits';
BEGIN
PERFORM create_partitioned_table(
'CREATE TABLE %I '
@@ -29,8 +29,7 @@ BEGIN
',partner_serial_id INT8'
',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)'
',coin_pub BYTEA NOT NULL'
- ',amount_with_fee_val INT8 NOT NULL'
- ',amount_with_fee_frac INT4 NOT NULL'
+ ',amount_with_fee taler_amount NOT NULL'
',coin_sig BYTEA NOT NULL CHECK(LENGTH(coin_sig)=64)'
',PRIMARY KEY (purse_pub,coin_pub)'
') %s ;'
@@ -63,7 +62,7 @@ BEGIN
);
PERFORM comment_partitioned_column(
'Total amount being deposited'
- ,'amount_with_fee_val'
+ ,'amount_with_fee'
,table_name
,partition_suffix
);
@@ -78,21 +77,16 @@ $$;
CREATE FUNCTION constrain_table_purse_deposits(
- IN partition_suffix VARCHAR
+ IN partition_suffix TEXT
)
RETURNS VOID
LANGUAGE plpgsql
AS $$
DECLARE
- table_name VARCHAR DEFAULT 'purse_deposits';
+ table_name TEXT DEFAULT 'purse_deposits';
BEGIN
table_name = concat_ws('_', table_name, partition_suffix);
- -- FIXME: change to materialized index by coin_pub!
- EXECUTE FORMAT (
- 'CREATE INDEX ' || table_name || '_by_coin_pub'
- ' ON ' || table_name || ' (coin_pub);'
- );
EXECUTE FORMAT (
'ALTER TABLE ' || table_name ||
' ADD CONSTRAINT ' || table_name || '_purse_deposit_serial_id_key'
@@ -107,7 +101,7 @@ RETURNS VOID
LANGUAGE plpgsql
AS $$
DECLARE
- table_name VARCHAR DEFAULT 'purse_deposits';
+ table_name TEXT DEFAULT 'purse_deposits';
BEGIN
EXECUTE FORMAT (
'ALTER TABLE ' || table_name ||
@@ -122,6 +116,37 @@ END
$$;
+CREATE OR REPLACE FUNCTION purse_deposits_insert_trigger()
+ RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+BEGIN
+ INSERT INTO exchange.coin_history
+ (coin_pub
+ ,table_name
+ ,serial_id)
+ VALUES
+ (NEW.coin_pub
+ ,'purse_deposits'
+ ,NEW.purse_deposit_serial_id);
+ RETURN NEW;
+END $$;
+COMMENT ON FUNCTION purse_deposits_insert_trigger()
+ IS 'Automatically generate coin history entry.';
+
+
+CREATE FUNCTION master_table_purse_deposits()
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ CREATE TRIGGER purse_deposits_on_insert
+ AFTER INSERT
+ ON purse_deposits
+ FOR EACH ROW EXECUTE FUNCTION purse_deposits_insert_trigger();
+END $$;
+
+
INSERT INTO exchange_tables
(name
,version
@@ -143,4 +168,9 @@ INSERT INTO exchange_tables
,'exchange-0002'
,'foreign'
,TRUE
+ ,FALSE),
+ ('purse_deposits'
+ ,'exchange-0002'
+ ,'master'
+ ,TRUE
,FALSE);