libeufin-bank-0007.sql (2015B)
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-bank-0007', NULL, NULL); 19 SET search_path TO libeufin_bank; 20 21 -- Make customer not null 22 -- Fill missing name with an empty string. All accounts created using the API already 23 -- have a non-null name, so this only applies to accounts created manually with SQL. 24 UPDATE customers SET name='' WHERE name is NULL; 25 ALTER TABLE customers ALTER COLUMN name SET NOT NULL; 26 27 -- Support all taler incoming transaction types 28 CREATE TYPE taler_incoming_type AS ENUM 29 ('reserve' ,'kyc', 'wad'); 30 ALTER TABLE taler_exchange_incoming 31 ADD type taler_incoming_type NOT NULL DEFAULT 'reserve', 32 ADD account_pub BYTEA CHECK (LENGTH(account_pub)=32), 33 ADD origin_exchange_url TEXT, 34 ADD wad_id BYTEA CHECK (LENGTH(wad_id)=24), 35 ALTER COLUMN reserve_pub DROP NOT NULL, 36 ADD CONSTRAINT incoming_polymorphism CHECK( 37 CASE type 38 WHEN 'reserve' THEN reserve_pub IS NOT NULL AND account_pub IS NULL AND origin_exchange_url IS NULL AND wad_id IS NULL 39 WHEN 'kyc' THEN reserve_pub IS NULL AND account_pub IS NOT NULL AND origin_exchange_url IS NULL AND wad_id IS NULL 40 WHEN 'wad' THEN reserve_pub IS NULL AND account_pub IS NULL AND origin_exchange_url IS NOT NULL AND wad_id IS NOT NULL 41 END 42 ); 43 ALTER TABLE taler_exchange_incoming ALTER COLUMN type DROP DEFAULT; 44 COMMIT;