merchant

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

pg_create_instance_trigger.sql (2528B)


      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.merchant_instances_after_insert_trigger() CASCADE;
     18 CREATE FUNCTION merchant.merchant_instances_after_insert_trigger()
     19   RETURNS trigger
     20   LANGUAGE plpgsql
     21   AS $$
     22 BEGIN
     23   PERFORM merchant.create_instance_schema(NEW.merchant_serial);
     24   IF NEW.email IS NOT NULL
     25   THEN
     26     CALL merchant.merchant_send_signup_notification(NEW.merchant_serial,
     27                                                     NEW.email);
     28   END IF;
     29   RETURN NEW;
     30 END $$;
     31 COMMENT ON FUNCTION merchant.merchant_instances_after_insert_trigger()
     32   IS 'Builds the per-instance schema merchant_instance_<merchant_serial>'
     33      ' for the newly inserted row and, if the instance has an e-mail'
     34      ' address, queues the sign-up message to it.';
     35 
     36 DROP TRIGGER IF EXISTS merchant_instances_on_insert
     37   ON merchant.merchant_instances;
     38 CREATE TRIGGER merchant_instances_on_insert
     39   AFTER INSERT
     40     ON merchant.merchant_instances
     41   FOR EACH ROW
     42   EXECUTE FUNCTION merchant.merchant_instances_after_insert_trigger();
     43 
     44 
     45 DROP FUNCTION IF EXISTS merchant.merchant_instances_after_delete_trigger() CASCADE;
     46 CREATE FUNCTION merchant.merchant_instances_after_delete_trigger()
     47   RETURNS trigger
     48   LANGUAGE plpgsql
     49   AS $$
     50 BEGIN
     51   EXECUTE format('DROP SCHEMA IF EXISTS %I CASCADE',
     52                  'merchant_instance_' || OLD.merchant_serial::TEXT);
     53   RETURN NULL;
     54 END $$;
     55 COMMENT ON FUNCTION merchant.merchant_instances_after_delete_trigger()
     56   IS 'Drops the per-instance schema merchant_instance_<merchant_serial>'
     57      ' when its row in merchant.merchant_instances is removed.';
     58 
     59 DROP TRIGGER IF EXISTS merchant_instances_on_delete
     60   ON merchant.merchant_instances;
     61 CREATE TRIGGER merchant_instances_on_delete
     62   AFTER DELETE ON merchant.merchant_instances
     63   FOR EACH ROW
     64   EXECUTE FUNCTION merchant.merchant_instances_after_delete_trigger();