select_all_donau_instances.sql (2781B)
1 -- 2 -- This file is part of TALER 3 -- Copyright (C) 2026 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 17 DROP FUNCTION IF EXISTS merchant.select_all_donau_instances(); 18 CREATE FUNCTION merchant.select_all_donau_instances() 19 RETURNS TABLE( 20 out_donau_instances_serial INT8, 21 out_donau_url TEXT, 22 out_charity_name TEXT, 23 out_charity_pub_key BYTEA, 24 out_charity_id INT8, 25 out_charity_max_per_year merchant.taler_amount_currency, 26 out_charity_receipts_to_date merchant.taler_amount_currency, 27 out_current_year INT8, 28 out_keys_json JSONB) 29 LANGUAGE plpgsql 30 AS $FN$ 31 DECLARE 32 rec RECORD; 33 s TEXT; 34 inner_rec RECORD; 35 BEGIN 36 FOR rec 37 IN 38 SELECT merchant_serial 39 ,merchant_pub 40 FROM merchant.merchant_instances 41 LOOP 42 s := 'merchant_instance_' || rec.merchant_serial::TEXT; 43 BEGIN 44 FOR inner_rec 45 IN 46 EXECUTE format( 47 'SELECT' 48 ' di.donau_instances_serial AS dis' 49 ' ,di.donau_url AS du' 50 ' ,di.charity_name AS cn' 51 ' ,di.charity_id AS ci' 52 ' ,di.charity_max_per_year AS cmp' 53 ' ,di.charity_receipts_to_date AS crt' 54 ' ,di.current_year AS cy' 55 ' ,dk.keys_json AS kj' 56 ' FROM %I.merchant_donau_instances di' 57 ' LEFT JOIN merchant.merchant_donau_keys dk' 58 ' ON di.donau_url = dk.donau_url', s) 59 LOOP 60 out_donau_instances_serial := inner_rec.dis; 61 out_donau_url := inner_rec.du; 62 out_charity_name := inner_rec.cn; 63 out_charity_pub_key := rec.merchant_pub; 64 out_charity_id := inner_rec.ci; 65 out_charity_max_per_year := inner_rec.cmp; 66 out_charity_receipts_to_date := inner_rec.crt; 67 out_current_year := inner_rec.cy; 68 out_keys_json := inner_rec.kj; 69 RETURN NEXT; 70 END LOOP; 71 EXCEPTION 72 WHEN undefined_table 73 THEN 74 NULL; 75 END; 76 END LOOP; 77 END 78 $FN$; 79 COMMENT ON FUNCTION merchant.select_all_donau_instances() 80 IS 'Returns all donau-instance configurations across every per-instance' 81 ' schema, joined with merchant.merchant_donau_keys for the keys json' 82 ' and with merchant.merchant_instances for the charity public key.';