commit 1ad546c050fe4c0c222d66d7d6ff8fed3b675f83
parent 3fd04d6aef941151819f87a2a7aeeb560938f230
Author: Christian Grothoff <grothoff@gnunet.org>
Date: Wed, 7 May 2025 17:19:24 +0200
merge legitimization_outcomes
Diffstat:
8 files changed, 372 insertions(+), 470 deletions(-)
diff --git a/src/exchangedb/0002-legitimization_measures.sql b/src/exchangedb/0002-legitimization_measures.sql
@@ -0,0 +1,147 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2024 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/>
+--
+
+CREATE FUNCTION create_table_legitimization_measures(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I'
+ '(legitimization_measure_serial_id INT8 GENERATED BY DEFAULT AS IDENTITY'
+ ',access_token BYTEA NOT NULL CHECK (LENGTH(access_token)=32)'
+ ',start_time INT8 NOT NULL'
+ ',jmeasures TEXT NOT NULL'
+ ',display_priority INT4 NOT NULL' -- DEAD?
+ ',is_finished BOOL NOT NULL DEFAULT(FALSE)'
+ ') %s ;'
+ ,'legitimization_measures'
+ ,'PARTITION BY HASH (access_token)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'List of required legitimizations by account'
+ ,'legitimization_measures'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'unique ID for this legitimization process at the exchange'
+ ,'legitimization_measure_serial_id'
+ ,'legitimization_measures'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'foreign key linking the entry to the wire_targets table, NOT a primary key (multiple legitimizations are possible per account)'
+ ,'access_token'
+ ,'legitimization_measures'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Time when the measure was triggered (by decision or rule)'
+ ,'start_time'
+ ,'legitimization_measures'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'JSON object of type LegitimizationMeasures with KYC/AML measures for the account encoded'
+ ,'jmeasures'
+ ,'legitimization_measures'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Display priority of the rule that triggered this measure; if in the meantime another rule also triggers, the measure is only replaced if the new rule has a higher display priority; probably not really useful, as right now there is only ever one set of legitimization_measures active at any time, might be removed in the future'
+ ,'display_priority'
+ ,'legitimization_measures'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Set to TRUE if this set of measures was processed; used to avoid indexing measures that are done'
+ ,'is_finished'
+ ,'legitimization_measures'
+ ,partition_suffix
+ );
+END
+$$;
+
+
+
+CREATE FUNCTION constrain_table_legitimization_measures(
+ IN partition_suffix TEXT
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'legitimization_measures';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_serial_id_key'
+ ' UNIQUE (legitimization_measure_serial_id)');
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_by_access_token'
+ ' ON ' || table_name ||
+ ' (access_token)'
+ ' WHERE NOT is_finished' ||
+ ';'
+ );
+END
+$$;
+
+
+CREATE FUNCTION foreign_table_legitimization_measures()
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'legitimization_measures';
+BEGIN
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_foreign_key_access_token'
+ ' FOREIGN KEY (access_token)'
+ ' REFERENCES wire_targets (access_token)'
+ ' ON DELETE CASCADE');
+END
+$$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('legitimization_measures'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('legitimization_measures'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('legitimization_measures'
+ ,'exchange-0002'
+ ,'foreign'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-legitimization_outcomes.sql b/src/exchangedb/0002-legitimization_outcomes.sql
@@ -0,0 +1,162 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2024 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/>
+--
+
+CREATE FUNCTION create_table_legitimization_outcomes(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I'
+ '(outcome_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',h_payto BYTEA NOT NULL CHECK (LENGTH(h_payto)=32)'
+ ',decision_time INT8 NOT NULL'
+ ',expiration_time INT8 NOT NULL'
+ ',jproperties TEXT'
+ ',new_measure_name TEXT'
+ ',to_investigate BOOL NOT NULL'
+ ',is_active BOOL NOT NULL DEFAULT(TRUE)'
+ ',jnew_rules TEXT'
+ ') %s ;'
+ ,'legitimization_outcomes'
+ ,'PARTITION BY HASH (h_payto)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'Outcomes of legitimization processes by account'
+ ,'legitimization_outcomes'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'unique ID for this legitimization outcome at the exchange'
+ ,'outcome_serial_id'
+ ,'legitimization_outcomes'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'hash of the payto://-URI this outcome is about; foreign key linking the entry to the wire_targets table, NOT a primary key (multiple outcomes are possible per account over time)'
+ ,'h_payto'
+ ,'legitimization_outcomes'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'when was this outcome decided, rounded timestamp'
+ ,'decision_time'
+ ,'legitimization_outcomes'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'space-separated list of names of measures to trigger immediately, NULL for none, prefixed with a "+" to indicate AND combination for the measures'
+ ,'new_measure_name'
+ ,'legitimization_outcomes'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'time when the decision expires and the expiration jnew_rules should be applied'
+ ,'expiration_time'
+ ,'legitimization_outcomes'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'JSON object of type AccountProperties, such as PEP status, business domain, risk assessment, etc.'
+ ,'jproperties'
+ ,'legitimization_outcomes'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'AML staff should investigate the activity of this account'
+ ,'to_investigate'
+ ,'legitimization_outcomes'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'TRUE if this is the current authoritative legitimization outcome'
+ ,'is_active'
+ ,'legitimization_outcomes'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'JSON object of type LegitimizationRuleSet with rules to apply to the various operation types for this account; all KYC checks should first check if active new rules for a given account exist in this table (and apply specified measures); if not, it should check the default rules to decide if a measure is required; NULL if the default rules apply'
+ ,'jnew_rules'
+ ,'legitimization_outcomes'
+ ,partition_suffix
+ );
+END
+$$;
+
+
+CREATE FUNCTION constrain_table_legitimization_outcomes(
+ IN partition_suffix TEXT
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'legitimization_outcomes';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_by_target_token'
+ ' ON ' || table_name ||
+ ' (h_payto)'
+ ' WHERE is_active' ||
+ ';'
+ );
+END
+$$;
+
+
+CREATE FUNCTION foreign_table_legitimization_outcomes()
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'legitimization_outcomes';
+BEGIN
+
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_serial_id_key'
+ ' UNIQUE (outcome_serial_id)');
+END
+$$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('legitimization_outcomes'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('legitimization_outcomes'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('legitimization_outcomes'
+ ,'exchange-0002'
+ ,'foreign'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-legitimization_processes.sql b/src/exchangedb/0002-legitimization_processes.sql
@@ -27,11 +27,15 @@ BEGIN
',h_payto BYTEA NOT NULL CHECK (LENGTH(h_payto)=32)'
',start_time INT8 NOT NULL'
',expiration_time INT8 NOT NULL DEFAULT (0)'
- ',provider_section TEXT NOT NULL'
+ ',provider_name TEXT NOT NULL'
',provider_user_id TEXT DEFAULT NULL'
',provider_legitimization_id TEXT DEFAULT NULL'
',redirect_url TEXT DEFAULT NULL'
',finished BOOLEAN DEFAULT (FALSE)'
+ ',legitimization_measure_serial_id BIGINT'
+ ',measure_index INT4 DEFAULT(0)'
+ ',error_code INT4 DEFAULT (0)'
+ ',error_message TEXT DEFAULT NULL'
') %s ;'
,'legitimization_processes'
,'PARTITION BY HASH (h_payto)'
@@ -74,7 +78,7 @@ BEGIN
);
PERFORM comment_partitioned_column(
'Configuration file section with details about this provider'
- ,'provider_section'
+ ,'provider_name'
,'legitimization_processes'
,shard_suffix
);
@@ -96,6 +100,30 @@ BEGIN
,'legitimization_processes'
,shard_suffix
);
+ PERFORM comment_partitioned_column(
+ 'measure that enabled this setup, NULL if client voluntarily initiated the process'
+ ,'legitimization_measure_serial_id'
+ ,'legitimization_processes'
+ ,shard_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'index of the measure in legitimization_measures that was selected for this KYC setup; NULL if legitimization_measure_serial_id is NULL; enables determination of the context data provided to the external process'
+ ,'measure_index'
+ ,'legitimization_processes'
+ ,shard_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'TALER_ErrorCode set if the process failed, otherwise NULL'
+ ,'error_code'
+ ,'legitimization_processes'
+ ,shard_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'human-readable error details set if the process failed, otherwise NULL'
+ ,'error_message'
+ ,'legitimization_processes'
+ ,shard_suffix
+ );
END
$$;
@@ -120,7 +148,7 @@ BEGIN
EXECUTE FORMAT (
'CREATE INDEX IF NOT EXISTS ' || partition_name || '_by_provider_and_legi_index '
'ON '|| partition_name || ' '
- '(provider_section,provider_legitimization_id)'
+ '(provider_name,provider_legitimization_id)'
);
EXECUTE FORMAT (
'COMMENT ON INDEX ' || partition_name || '_by_provider_and_legi_index '
@@ -130,6 +158,30 @@ END
$$;
+-- We need a separate function for this, as we call create_table only once but need to add
+-- those constraints to each partition which gets created
+CREATE FUNCTION foreign_table_legitimization_processes()
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'legitimization_processes';
+BEGIN
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_foreign_key_legitimization_measure'
+ ' FOREIGN KEY (legitimization_measure_serial_id)'
+ ' REFERENCES legitimization_measures (legitimization_measure_serial_id)');
+
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_unique_measure_and_index'
+ ' UNIQUE (legitimization_measure_serial_id,measure_index)');
+END
+$$;
+
+
+
INSERT INTO exchange_tables
(name
,version
@@ -146,4 +198,10 @@ INSERT INTO exchange_tables
,'exchange-0002'
,'constrain'
,TRUE
+ ,FALSE),
+ ('legitimization_processes5'
+ ,'exchange-0002'
+ ,'foreign'
+ ,TRUE
,FALSE);
+
diff --git a/src/exchangedb/0005-legitimization_measures.sql b/src/exchangedb/0005-legitimization_measures.sql
@@ -1,147 +0,0 @@
---
--- This file is part of TALER
--- Copyright (C) 2024 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/>
---
-
-CREATE FUNCTION create_table_legitimization_measures(
- IN partition_suffix TEXT DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
- PERFORM create_partitioned_table(
- 'CREATE TABLE %I'
- '(legitimization_measure_serial_id INT8 GENERATED BY DEFAULT AS IDENTITY'
- ',access_token BYTEA NOT NULL CHECK (LENGTH(access_token)=32)'
- ',start_time INT8 NOT NULL'
- ',jmeasures TEXT NOT NULL'
- ',display_priority INT4 NOT NULL' -- DEAD?
- ',is_finished BOOL NOT NULL DEFAULT(FALSE)'
- ') %s ;'
- ,'legitimization_measures'
- ,'PARTITION BY HASH (access_token)'
- ,partition_suffix
- );
- PERFORM comment_partitioned_table(
- 'List of required legitimizations by account'
- ,'legitimization_measures'
- ,partition_suffix
- );
- PERFORM comment_partitioned_column(
- 'unique ID for this legitimization process at the exchange'
- ,'legitimization_measure_serial_id'
- ,'legitimization_measures'
- ,partition_suffix
- );
- PERFORM comment_partitioned_column(
- 'foreign key linking the entry to the wire_targets table, NOT a primary key (multiple legitimizations are possible per account)'
- ,'access_token'
- ,'legitimization_measures'
- ,partition_suffix
- );
- PERFORM comment_partitioned_column(
- 'Time when the measure was triggered (by decision or rule)'
- ,'start_time'
- ,'legitimization_measures'
- ,partition_suffix
- );
- PERFORM comment_partitioned_column(
- 'JSON object of type LegitimizationMeasures with KYC/AML measures for the account encoded'
- ,'jmeasures'
- ,'legitimization_measures'
- ,partition_suffix
- );
- PERFORM comment_partitioned_column(
- 'Display priority of the rule that triggered this measure; if in the meantime another rule also triggers, the measure is only replaced if the new rule has a higher display priority; probably not really useful, as right now there is only ever one set of legitimization_measures active at any time, might be removed in the future'
- ,'display_priority'
- ,'legitimization_measures'
- ,partition_suffix
- );
- PERFORM comment_partitioned_column(
- 'Set to TRUE if this set of measures was processed; used to avoid indexing measures that are done'
- ,'is_finished'
- ,'legitimization_measures'
- ,partition_suffix
- );
-END
-$$;
-
-
-
-CREATE FUNCTION constrain_table_legitimization_measures(
- IN partition_suffix TEXT
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name TEXT DEFAULT 'legitimization_measures';
-BEGIN
- table_name = concat_ws('_', table_name, partition_suffix);
-
- EXECUTE FORMAT (
- 'ALTER TABLE ' || table_name ||
- ' ADD CONSTRAINT ' || table_name || '_serial_id_key'
- ' UNIQUE (legitimization_measure_serial_id)');
- EXECUTE FORMAT (
- 'CREATE INDEX ' || table_name || '_by_access_token'
- ' ON ' || table_name ||
- ' (access_token)'
- ' WHERE NOT is_finished' ||
- ';'
- );
-END
-$$;
-
-
-CREATE FUNCTION foreign_table_legitimization_measures()
-RETURNS void
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name TEXT DEFAULT 'legitimization_measures';
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE ' || table_name ||
- ' ADD CONSTRAINT ' || table_name || '_foreign_key_access_token'
- ' FOREIGN KEY (access_token)'
- ' REFERENCES wire_targets (access_token)'
- ' ON DELETE CASCADE');
-END
-$$;
-
-
-INSERT INTO exchange_tables
- (name
- ,version
- ,action
- ,partitioned
- ,by_range)
- VALUES
- ('legitimization_measures'
- ,'exchange-0005'
- ,'create'
- ,TRUE
- ,FALSE),
- ('legitimization_measures'
- ,'exchange-0005'
- ,'constrain'
- ,TRUE
- ,FALSE),
- ('legitimization_measures'
- ,'exchange-0005'
- ,'foreign'
- ,TRUE
- ,FALSE);
diff --git a/src/exchangedb/0005-legitimization_outcomes.sql b/src/exchangedb/0005-legitimization_outcomes.sql
@@ -1,168 +0,0 @@
---
--- This file is part of TALER
--- Copyright (C) 2024 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/>
---
-
-CREATE FUNCTION create_table_legitimization_outcomes(
- IN partition_suffix TEXT DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
- PERFORM create_partitioned_table(
- 'CREATE TABLE %I'
- '(outcome_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
- ',h_payto BYTEA NOT NULL CHECK (LENGTH(h_payto)=32)'
- ',decision_time INT8 NOT NULL'
- ',expiration_time INT8 NOT NULL'
- ',jproperties TEXT'
- ',new_measure_name TEXT'
- ',to_investigate BOOL NOT NULL'
- ',is_active BOOL NOT NULL DEFAULT(TRUE)'
- ',jnew_rules TEXT'
- ') %s ;'
- ,'legitimization_outcomes'
- ,'PARTITION BY HASH (h_payto)'
- ,partition_suffix
- );
- PERFORM comment_partitioned_table(
- 'Outcomes of legitimization processes by account'
- ,'legitimization_outcomes'
- ,partition_suffix
- );
- PERFORM comment_partitioned_column(
- 'unique ID for this legitimization outcome at the exchange'
- ,'outcome_serial_id'
- ,'legitimization_outcomes'
- ,partition_suffix
- );
- PERFORM comment_partitioned_column(
- 'hash of the payto://-URI this outcome is about; foreign key linking the entry to the wire_targets table, NOT a primary key (multiple outcomes are possible per account over time)'
- ,'h_payto'
- ,'legitimization_outcomes'
- ,partition_suffix
- );
- PERFORM comment_partitioned_column(
- 'when was this outcome decided, rounded timestamp'
- ,'decision_time'
- ,'legitimization_outcomes'
- ,partition_suffix
- );
- PERFORM comment_partitioned_column(
- 'space-separated list of names of measures to trigger immediately, NULL for none, prefixed with a "+" to indicate AND combination for the measures'
- ,'new_measure_name'
- ,'legitimization_outcomes'
- ,partition_suffix
- );
- PERFORM comment_partitioned_column(
- 'time when the decision expires and the expiration jnew_rules should be applied'
- ,'expiration_time'
- ,'legitimization_outcomes'
- ,partition_suffix
- );
- PERFORM comment_partitioned_column(
- 'JSON object of type AccountProperties, such as PEP status, business domain, risk assessment, etc.'
- ,'jproperties'
- ,'legitimization_outcomes'
- ,partition_suffix
- );
- PERFORM comment_partitioned_column(
- 'AML staff should investigate the activity of this account'
- ,'to_investigate'
- ,'legitimization_outcomes'
- ,partition_suffix
- );
- PERFORM comment_partitioned_column(
- 'TRUE if this is the current authoritative legitimization outcome'
- ,'is_active'
- ,'legitimization_outcomes'
- ,partition_suffix
- );
- PERFORM comment_partitioned_column(
- 'JSON object of type LegitimizationRuleSet with rules to apply to the various operation types for this account; all KYC checks should first check if active new rules for a given account exist in this table (and apply specified measures); if not, it should check the default rules to decide if a measure is required; NULL if the default rules apply'
- ,'jnew_rules'
- ,'legitimization_outcomes'
- ,partition_suffix
- );
-END
-$$;
-
-
-CREATE FUNCTION constrain_table_legitimization_outcomes(
- IN partition_suffix TEXT
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name TEXT DEFAULT 'legitimization_outcomes';
-BEGIN
- table_name = concat_ws('_', table_name, partition_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX ' || table_name || '_by_target_token'
- ' ON ' || table_name ||
- ' (h_payto)'
- ' WHERE is_active' ||
- ';'
- );
-END
-$$;
-
-
-CREATE FUNCTION foreign_table_legitimization_outcomes()
-RETURNS void
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name TEXT DEFAULT 'legitimization_outcomes';
-BEGIN
-
- EXECUTE FORMAT (
- 'ALTER TABLE ' || table_name ||
- ' ADD CONSTRAINT ' || table_name || '_serial_id_key'
- ' UNIQUE (outcome_serial_id)');
-
- EXECUTE FORMAT (
- 'ALTER TABLE ' || table_name ||
- ' ADD CONSTRAINT ' || table_name || '_foreign_key_h_payto'
- ' FOREIGN KEY (h_payto)'
- ' REFERENCES wire_targets (wire_target_h_payto) ON DELETE CASCADE');
-END
-$$;
-
-
-INSERT INTO exchange_tables
- (name
- ,version
- ,action
- ,partitioned
- ,by_range)
- VALUES
- ('legitimization_outcomes'
- ,'exchange-0005'
- ,'create'
- ,TRUE
- ,FALSE),
- ('legitimization_outcomes'
- ,'exchange-0005'
- ,'constrain'
- ,TRUE
- ,FALSE),
- ('legitimization_outcomes'
- ,'exchange-0005'
- ,'foreign'
- ,TRUE
- ,FALSE);
diff --git a/src/exchangedb/0005-legitimization_processes.sql b/src/exchangedb/0005-legitimization_processes.sql
@@ -1,109 +0,0 @@
---
--- This file is part of TALER
--- Copyright (C) 2024 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/>
---
-
-CREATE FUNCTION alter_table_legitimization_processes5(
- IN shard_suffix TEXT DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
- PERFORM create_partitioned_table(
- 'ALTER TABLE %I'
- ' ADD COLUMN legitimization_measure_serial_id BIGINT'
- ',ADD COLUMN measure_index INT4 DEFAULT(0)'
- ',ADD COLUMN error_code INT4 DEFAULT (0)'
- ',ADD COLUMN error_message TEXT DEFAULT NULL'
- ';'
- ,'legitimization_processes'
- ,''
- ,shard_suffix
- );
- PERFORM create_partitioned_table(
- 'ALTER TABLE %I'
- ' RENAME provider_section TO provider_name'
- ';'
- ,'legitimization_processes'
- ,''
- ,shard_suffix
- );
- PERFORM comment_partitioned_column(
- 'measure that enabled this setup, NULL if client voluntarily initiated the process'
- ,'legitimization_measure_serial_id'
- ,'legitimization_processes'
- ,shard_suffix
- );
- PERFORM comment_partitioned_column(
- 'index of the measure in legitimization_measures that was selected for this KYC setup; NULL if legitimization_measure_serial_id is NULL; enables determination of the context data provided to the external process'
- ,'measure_index'
- ,'legitimization_processes'
- ,shard_suffix
- );
- PERFORM comment_partitioned_column(
- 'TALER_ErrorCode set if the process failed, otherwise NULL'
- ,'error_code'
- ,'legitimization_processes'
- ,shard_suffix
- );
- PERFORM comment_partitioned_column(
- 'human-readable error details set if the process failed, otherwise NULL'
- ,'error_message'
- ,'legitimization_processes'
- ,shard_suffix
- );
-END
-$$;
-
--- We need a separate function for this, as we call create_table only once but need to add
--- those constraints to each partition which gets created
-CREATE FUNCTION foreign_table_legitimization_processes5()
-RETURNS void
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name TEXT DEFAULT 'legitimization_processes';
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE ' || table_name ||
- ' ADD CONSTRAINT ' || table_name || '_foreign_key_legitimization_measure'
- ' FOREIGN KEY (legitimization_measure_serial_id)'
- ' REFERENCES legitimization_measures (legitimization_measure_serial_id)');
-
- EXECUTE FORMAT (
- 'ALTER TABLE ' || table_name ||
- ' ADD CONSTRAINT ' || table_name || '_unique_measure_and_index'
- ' UNIQUE (legitimization_measure_serial_id,measure_index)');
-END
-$$;
-
-
-INSERT INTO exchange_tables
- (name
- ,version
- ,action
- ,partitioned
- ,by_range)
- VALUES
- ('legitimization_processes5'
- ,'exchange-0005'
- ,'alter'
- ,TRUE
- ,FALSE),
- ('legitimization_processes5'
- ,'exchange-0005'
- ,'foreign'
- ,TRUE
- ,FALSE);
diff --git a/src/exchangedb/0007-legitimization_outcomes.sql b/src/exchangedb/0007-legitimization_outcomes.sql
@@ -1,43 +0,0 @@
---
--- This file is part of TALER
--- Copyright (C) 2024 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/>
---
-
-CREATE FUNCTION foreign_table_legitimization_outcomes7()
-RETURNS void
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name TEXT DEFAULT 'legitimization_outcomes';
-BEGIN
-
- EXECUTE FORMAT (
- 'ALTER TABLE ' || table_name ||
- ' DROP CONSTRAINT ' || table_name || '_foreign_key_h_payto');
-END
-$$;
-
-
-INSERT INTO exchange_tables
- (name
- ,version
- ,action
- ,partitioned
- ,by_range)
- VALUES
- ('legitimization_outcomes7'
- ,'exchange-0007'
- ,'foreign'
- ,TRUE
- ,FALSE);
diff --git a/src/exchangedb/exchange-0002.sql.in b/src/exchangedb/exchange-0002.sql.in
@@ -66,6 +66,8 @@ COMMENT ON TYPE exchange_do_select_deposits_missing_wire_return_type
#include "0002-policy_fulfillments.sql"
#include "0002-policy_details.sql"
#include "0002-profit_drains.sql"
+#include "0002-legitimization_measures.sql"
+#include "0002-legitimization_outcomes.sql"
#include "0002-legitimization_processes.sql"
#include "0002-legitimization_requirements.sql"
#include "0002-reserves.sql"