pg_merchant_account_trigger.sql (1426B)
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 -- @file pg_merchant_account_trigger.sql 17 -- @brief Run on INSERT/DELETE/UPDATE of accounts to generate report 18 -- @author Christian Grothoff 19 20 21 CREATE OR REPLACE FUNCTION merchant_account_change_trigger() 22 RETURNS trigger 23 LANGUAGE plpgsql 24 AS $$ 25 BEGIN 26 IF TG_OP = 'DELETE' 27 THEN 28 -- The row is already gone, merchant_send_account_notification() 29 -- could no longer resolve the account. 30 RETURN NULL; 31 END IF; 32 -- Note: on INSERT the OLD record is NULL, so a newly added account 33 -- is reported as a change as well. 34 IF (OLD.payto_uri 35 ,OLD.active) 36 IS DISTINCT FROM 37 (NEW.payto_uri 38 ,NEW.active) 39 THEN 40 CALL merchant_send_account_notification(NEW.account_serial); 41 END IF; 42 RETURN NULL; 43 END $$;