libeufin

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

libeufin-bank-0012.sql (1652B)


      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-bank-0012', NULL, NULL);
     19 SET search_path TO libeufin_bank;
     20 
     21 -- Add no_amount_to_wallet for withdrawal
     22 ALTER TABLE taler_withdrawal_operations ADD COLUMN no_amount_to_wallet BOOLEAN DEFAULT false;
     23 
     24 -- Better polymorphism schema
     25 ALTER TABLE taler_exchange_incoming ADD COLUMN metadata BYTEA;
     26 UPDATE taler_exchange_incoming SET metadata=COALESCE(reserve_pub, account_pub, wad_id);
     27 ALTER TABLE taler_exchange_incoming
     28   DROP CONSTRAINT incoming_polymorphism,
     29   DROP COLUMN reserve_pub,
     30   DROP COLUMN account_pub,
     31   DROP COLUMN wad_id,
     32   ALTER COLUMN metadata SET NOT NULL,
     33   ADD CONSTRAINT polymorphism CHECK(
     34     CASE type
     35       WHEN 'wad' THEN LENGTH(metadata)=24 AND origin_exchange_url IS NOT NULL
     36       ELSE LENGTH(metadata)=32 AND origin_exchange_url IS NULL
     37     END
     38   );
     39 CREATE UNIQUE INDEX taler_exchange_incoming_unique_reserve_pub ON taler_exchange_incoming (metadata) WHERE type = 'reserve';
     40 
     41 COMMIT;