libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

libeufin-nexus-0011.sql (1660B)


      1 --
      2 -- This file is part of TALER
      3 -- Copyright (C) 2025 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 BEGIN;
     17 
     18 SELECT _v.register_patch('libeufin-nexus-0011', NULL, NULL);
     19 
     20 SET search_path TO libeufin_nexus;
     21 
     22 ALTER TABLE outgoing_transactions
     23   ADD COLUMN acct_svcr_ref TEXT UNIQUE,
     24   ALTER COLUMN end_to_end_id DROP NOT NULL,
     25   ADD CONSTRAINT unique_id CHECK(COALESCE(end_to_end_id, acct_svcr_ref) IS NOT NULL);
     26 
     27 ALTER TABLE incoming_transactions
     28   ADD COLUMN uetr UUID UNIQUE,
     29   ADD COLUMN tx_id TEXT UNIQUE,
     30   ADD COLUMN acct_svcr_ref TEXT UNIQUE;
     31 
     32 UPDATE incoming_transactions SET 
     33   uetr = CASE WHEN bank_id ~ E'^[[:xdigit:]]{8}-([[:xdigit:]]{4}-){3}[[:xdigit:]]{12}$' THEN bank_id::uuid ELSE NULL END,
     34   tx_id = CASE WHEN bank_id ~ E'^[[:xdigit:]]{8}-([[:xdigit:]]{4}-){3}[[:xdigit:]]{12}$' THEN NULL ELSE bank_id END;
     35 
     36 ALTER TABLE incoming_transactions
     37   DROP COLUMN bank_id,
     38   ALTER COLUMN subject DROP NOT NULL,
     39   ALTER COLUMN debit_payto DROP NOT NULL,
     40   ADD CONSTRAINT unique_id CHECK(COALESCE(uetr::text, tx_id, acct_svcr_ref) IS NOT NULL);
     41 
     42 COMMIT;