merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

pg_create_instance_schema.sql (1695B)


      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.create_instance_schema;
     18 CREATE FUNCTION merchant.create_instance_schema(
     19   in_merchant_serial BIGINT
     20 )
     21   RETURNS void
     22   LANGUAGE plpgsql
     23   AS $$
     24 DECLARE
     25   s TEXT := 'merchant_instance_' || in_merchant_serial::TEXT;
     26   r RECORD;
     27 BEGIN
     28   EXECUTE format('CREATE SCHEMA %I', s);
     29 
     30   -- Call fixup functions to initialize all tables
     31   FOR r IN
     32     SELECT migration_name
     33       FROM merchant.instance_fixups
     34      ORDER BY version ASC
     35   LOOP
     36     EXECUTE FORMAT ('CALL merchant.%I(%L)', r.migration_name, s);
     37   END LOOP;
     38   EXECUTE FORMAT ('CALL merchant.sync_instance_procedures(%s)', in_merchant_serial);
     39 END $$;
     40 
     41 COMMENT ON FUNCTION merchant.create_instance_schema(BIGINT)
     42   IS 'Constructs the per-instance schema merchant_instance_<merchant_serial>'
     43      ' with all per-instance tables, stored procedures and triggers.  Called from'
     44      ' merchant_instances_after_insert_trigger() whenever a new instance row'
     45      ' is inserted into merchant.merchant_instances.';