libeufin-nexus-0010.sql (1674B)
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-0010', NULL, NULL); 19 20 SET search_path TO libeufin_nexus; 21 22 -- Better polymorphism schema 23 ALTER TABLE talerable_incoming_transactions ADD COLUMN metadata BYTEA; 24 UPDATE talerable_incoming_transactions 25 SET metadata=COALESCE (reserve_public_key, account_pub, wad_id); 26 ALTER TABLE talerable_incoming_transactions 27 DROP CONSTRAINT incoming_polymorphism, 28 DROP COLUMN reserve_public_key, 29 DROP COLUMN account_pub, 30 DROP COLUMN wad_id, 31 ALTER COLUMN metadata SET NOT NULL, 32 ADD CONSTRAINT polymorphism CHECK( 33 CASE type 34 WHEN 'wad' THEN LENGTH(metadata)=24 AND origin_exchange_url IS NOT NULL 35 ELSE LENGTH(metadata)=32 AND origin_exchange_url IS NULL 36 END 37 ); 38 CREATE INDEX talerable_incoming_polymorphism ON talerable_incoming_transactions (type, metadata); 39 CREATE UNIQUE INDEX talerable_incoming_transactions_unique_reserve_pub ON talerable_incoming_transactions (metadata) WHERE type = 'reserve'; 40 41 COMMIT;