libeufin

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

libeufin-nexus-0006.sql (2222B)


      1 --
      2 -- This file is part of TALER
      3 -- Copyright (C) 2024 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-0006', NULL, NULL);
     19 
     20 SET search_path TO libeufin_nexus;
     21 
     22 -- Support all taler incoming transaction types
     23 CREATE TYPE taler_incoming_type AS ENUM
     24   ('reserve' ,'kyc', 'wad');
     25 ALTER TABLE talerable_incoming_transactions
     26   ADD type taler_incoming_type NOT NULL DEFAULT 'reserve',
     27   ADD account_pub BYTEA CHECK (LENGTH(account_pub)=32),
     28   ADD origin_exchange_url TEXT,
     29   ADD wad_id BYTEA CHECK (LENGTH(wad_id)=24),
     30   ALTER COLUMN reserve_public_key DROP NOT NULL,
     31   ADD CONSTRAINT incoming_polymorphism CHECK(
     32     CASE type
     33       WHEN 'reserve' THEN reserve_public_key IS NOT NULL AND account_pub IS NULL AND origin_exchange_url IS NULL AND wad_id IS NULL
     34       WHEN 'kyc' THEN reserve_public_key IS NULL AND account_pub IS NOT NULL AND origin_exchange_url IS NULL AND wad_id IS NULL
     35       WHEN 'wad' THEN reserve_public_key IS NULL AND account_pub IS NULL AND origin_exchange_url IS NOT NULL AND wad_id IS NOT NULL
     36     END
     37   );
     38 ALTER TABLE talerable_incoming_transactions ALTER COLUMN type DROP DEFAULT;
     39 
     40 CREATE INDEX talerable_incoming_transactions_kyc_index ON talerable_incoming_transactions (account_pub) WHERE account_pub IS NOT NULL;
     41 COMMENT ON INDEX talerable_incoming_transactions_kyc_index IS 'for reconciling KYC transaction without bank_id';
     42 
     43 CREATE INDEX initiated_outgoing_transactions_status_index ON initiated_outgoing_transactions (submitted);
     44 COMMENT ON INDEX initiated_outgoing_transactions_status_index IS 'for listing taler transfers by status';
     45 
     46 COMMIT;