exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

commit 54cf6f7527d571e7c376e711e1a49a939161c525
parent 2c0b6d734456bd566634c15108feffa3dc7bf737
Author: Christian Grothoff <grothoff@gnunet.org>
Date:   Wed, 19 Mar 2025 09:02:38 +0100

add missing indices and constraints

Diffstat:
Msrc/exchangedb/0002-aggregation_transient.sql | 15+++++++++++++--
Msrc/exchangedb/Makefile.am | 4+++-
Msrc/exchangedb/exchange-0001.sql | 1-
Asrc/exchangedb/exchange-0009.sql | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 97 insertions(+), 4 deletions(-)

diff --git a/src/exchangedb/0002-aggregation_transient.sql b/src/exchangedb/0002-aggregation_transient.sql @@ -1,6 +1,6 @@ -- -- This file is part of TALER --- Copyright (C) 2014--2022 Taler Systems SA +-- Copyright (C) 2014--2025 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 @@ -48,6 +48,18 @@ BEGIN ,shard_suffix ); PERFORM comment_partitioned_column( + 'public key of the merchant that authorized the deposits' + ,'merchant_pub' + ,table_name + ,shard_suffix + ); + PERFORM comment_partitioned_column( + 'unsalted hash of the (full) payto URI of the merchant account that should receive the funds' + ,'wire_target_h_payto' + ,table_name + ,shard_suffix + ); + PERFORM comment_partitioned_column( 'identifier of the wire transfer' ,'wtid_raw' ,table_name @@ -56,7 +68,6 @@ BEGIN END $$; - INSERT INTO exchange_tables (name ,version diff --git a/src/exchangedb/Makefile.am b/src/exchangedb/Makefile.am @@ -36,7 +36,8 @@ sqlinputs = \ exchange-0005.sql.in \ exchange-0006.sql.in \ exchange-0007.sql.in \ - exchange-0008.sql.in + exchange-0008.sql.in \ + exchange-0009.sql sql_DATA = \ benchmark-0001.sql \ @@ -50,6 +51,7 @@ sql_DATA = \ exchange-0006.sql \ exchange-0007.sql \ exchange-0008.sql \ + exchange-0009.sql \ drop.sql \ procedures.sql diff --git a/src/exchangedb/exchange-0001.sql b/src/exchangedb/exchange-0001.sql @@ -50,5 +50,4 @@ COMMENT ON COLUMN exchange_tables.by_range COMMENT ON COLUMN exchange_tables.finished IS 'TRUE if the respective migration has been run'; - COMMIT; diff --git a/src/exchangedb/exchange-0009.sql b/src/exchangedb/exchange-0009.sql @@ -0,0 +1,81 @@ +-- +-- This file is part of TALER +-- Copyright (C) 2025 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 +-- Foundation; either version 3, or (at your option) any later version. +-- +-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY +-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +-- A PARTICULAR PURPOSE. See the GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License along with +-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +-- + +BEGIN; + +SELECT _v.register_patch('exchange-0009', NULL, NULL); + +SET search_path TO exchange; + +CREATE INDEX exchange_tables_by_pending + ON exchange_tables (table_serial_id) + WHERE NOT finished; +COMMENT ON INDEX exchange_tables_by_pending + IS 'Used by exchange_do_create_tables'; + +CREATE FUNCTION foreign_table_aggregation_transient9() +RETURNS void +LANGUAGE plpgsql +AS $$ +DECLARE + table_name TEXT DEFAULT 'aggregation_transient'; +BEGIN + EXECUTE FORMAT ( + 'ALTER TABLE ' || table_name || + ' ADD CONSTRAINT ' || table_name || '_foreign_wire_target_h_payto' + ' FOREIGN KEY (wire_target_h_payto) ' + ' REFERENCES wire_targets (wire_target_h_payto) ON DELETE RESTRICT' + ); +END +$$; + +CREATE FUNCTION constrain_table_aggregation_transient9( + IN partition_suffix TEXT +) +RETURNS VOID +LANGUAGE plpgsql +AS $$ +DECLARE + table_name TEXT DEFAULT 'aggregation_transient'; +BEGIN + table_name = concat_ws('_', table_name, partition_suffix); + EXECUTE FORMAT ( + 'ALTER TABLE ' || table_name || + ' ADD CONSTRAINT ' || table_name || '_wire_target_h_payto_and_wtid_unique' + ' UNIQUE (wire_target_h_payto,wtid_raw)' + ); +END $$; + + +INSERT INTO exchange_tables + (name + ,version + ,action + ,partitioned + ,by_range) + VALUES + ('aggregation_transient9' + ,'exchange-0009' + ,'foreign' + ,TRUE + ,FALSE), + ('aggregation_transient9' + ,'exchange-0009' + ,'constrain' + ,TRUE + ,FALSE); + +COMMIT;