35 lines
790 B
MySQL
35 lines
790 B
MySQL
|
-- Deploy numerus:remove_expense to pg
|
||
|
-- requires: roles
|
||
|
-- requires: schema_numerus
|
||
|
-- requires: expense_tax
|
||
|
-- requires: expense_attachment
|
||
|
-- requires: expense
|
||
|
|
||
|
begin;
|
||
|
|
||
|
set search_path to numerus, public;
|
||
|
|
||
|
create or replace function remove_expense(expense_slug uuid) returns void as
|
||
|
$$
|
||
|
declare
|
||
|
eid integer;
|
||
|
begin
|
||
|
select expense_id into eid from expense where slug = expense_slug;
|
||
|
if not found then
|
||
|
return;
|
||
|
end if;
|
||
|
|
||
|
delete from expense_tax where expense_id = eid;
|
||
|
delete from expense_attachment where expense_id = eid;
|
||
|
delete from expense where expense_id = eid;
|
||
|
end
|
||
|
$$
|
||
|
language plpgsql
|
||
|
;
|
||
|
|
||
|
revoke execute on function remove_expense(uuid) from public;
|
||
|
grant execute on function remove_expense(uuid) to invoicer;
|
||
|
grant execute on function remove_expense(uuid) to admin;
|
||
|
|
||
|
commit;
|