pg_fixup_instance_schema.sql (1488B)
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 PROCEDURE IF EXISTS merchant.fixup_instance_schema(BIGINT); 18 CREATE PROCEDURE merchant.fixup_instance_schema( 19 in_min_version BIGINT 20 ) 21 LANGUAGE plpgsql 22 AS $$ 23 DECLARE 24 rec RECORD; 25 r RECORD; 26 my_schema_name TEXT; 27 BEGIN 28 FOR rec IN 29 SELECT merchant_serial 30 FROM merchant.merchant_instances 31 LOOP 32 my_schema_name := 'merchant_instance_' || rec.merchant_serial::TEXT; 33 -- Call fixup functions 34 FOR r IN 35 SELECT migration_name 36 FROM merchant.instance_fixups 37 WHERE version >= in_min_version 38 ORDER BY version ASC 39 LOOP 40 EXECUTE format('CALL %I(%I)', r.migration_name, my_schema_name); 41 END LOOP; 42 END LOOP; 43 END $$; 44 45 COMMENT ON PROCEDURE merchant.fixup_instance_schema(BIGINT) 46 IS 'Updates all schema to the given version';