donau

Donation authority for GNU Taler (experimental)
Log | Files | Refs | Submodules | README | LICENSE

delete_charity.sql (1514B)


      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 do_delete_charity;
     18 CREATE FUNCTION do_delete_charity (
     19    IN in_charity_id INT8
     20   ,OUT out_found BOOLEAN
     21   ,OUT out_in_use BOOLEAN
     22 )
     23 LANGUAGE plpgsql
     24 AS $$
     25 BEGIN
     26   out_in_use = FALSE;
     27   DELETE FROM charities
     28    WHERE charity_id=in_charity_id;
     29   out_found = FOUND;
     30 EXCEPTION
     31   WHEN foreign_key_violation THEN
     32     -- receipts_issued references this charity with ON DELETE RESTRICT,
     33     -- because receipts_issued.receipt_hash is the idempotence key of
     34     -- POST /batch-issue and must outlive the charity row.
     35     out_found = TRUE;
     36     out_in_use = TRUE;
     37 END $$;
     38 
     39 COMMENT ON FUNCTION do_delete_charity
     40   IS 'Deletes a charity. out_found is FALSE if no charity with the given charity_id exists; out_in_use is TRUE if the charity still has issued receipts and was therefore NOT deleted.';