exchange

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

exchange-0021.sql (2671B)


      1 --
      2 -- This file is part of TALER
      3 -- Copyright (C) 2026 Taler Systems SA
      4 --
      5 -- TALER is free software; you can redistribute it and/or modify it under the
      6 -- terms of the GNU General Public License as published by the Free Software
      7 -- Foundation; either version 3, or (at your option) any later version.
      8 --
      9 -- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
     10 -- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11 -- A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     12 --
     13 -- You should have received a copy of the GNU General Public License along with
     14 -- TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15 --
     16 
     17 
     18 BEGIN;
     19 
     20 SELECT _v.register_patch('exchange-0021', NULL, NULL);
     21 
     22 SET search_path TO exchange;
     23 
     24 
     25 -- A KYC process may return several attribute sets, one per form (each
     26 -- with its own FORM_ID), and each set is stored as a row of its own.
     27 -- form_index numbers the sets of one process in the order the provider
     28 -- returned them, so that their order does not depend on row IDs or
     29 -- collection times; the set with index 0 is the primary one.  Rows from
     30 -- before this patch are the only set of their process: index 0.  The
     31 -- UNIQUE (h_payto, legitimization_serial) constraint of exchange-0004
     32 -- becomes one over (h_payto, legitimization_serial, form_index): each
     33 -- set of a process is still stored only once.
     34 
     35 CREATE FUNCTION alter_table_kyc_attributes21()
     36 RETURNS void
     37 LANGUAGE plpgsql
     38 AS $$
     39 BEGIN
     40   ALTER TABLE kyc_attributes
     41     ADD COLUMN form_index INT4 NOT NULL DEFAULT (0);
     42   COMMENT ON COLUMN kyc_attributes.form_index
     43     IS 'position of these attributes in the list of attribute sets the legitimization process returned, starting at 0 (the primary set); 0 for a process that returned a single set';
     44 END
     45 $$;
     46 
     47 CREATE FUNCTION constrain_table_kyc_attributes21(
     48   IN partition_suffix TEXT
     49 )
     50 RETURNS void
     51 LANGUAGE plpgsql
     52 AS $$
     53 DECLARE
     54   table_name TEXT DEFAULT 'kyc_attributes';
     55 BEGIN
     56   table_name = concat_ws('_', table_name, partition_suffix);
     57   EXECUTE FORMAT (
     58     'ALTER TABLE ' || table_name ||
     59       ' DROP CONSTRAINT ' || table_name || '_legitimization_serial'
     60   );
     61   EXECUTE FORMAT (
     62     'ALTER TABLE ' || table_name ||
     63       ' ADD CONSTRAINT ' || table_name || '_legitimization_serial_form_index '
     64         'UNIQUE (h_payto,legitimization_serial,form_index)'
     65   );
     66 END $$;
     67 
     68 INSERT INTO exchange_tables
     69     (name
     70     ,version
     71     ,action
     72     ,partitioned
     73     ,by_range)
     74   VALUES
     75     ('kyc_attributes21'
     76     ,'exchange-0021'
     77     ,'alter'
     78     ,TRUE
     79     ,FALSE),
     80     ('kyc_attributes21'
     81     ,'exchange-0021'
     82     ,'constrain'
     83     ,TRUE
     84     ,FALSE);
     85 
     86 COMMIT;