Skip to content

Commit 236d7a0

Browse files
authored
feat: add trigger function for managing activity on account transfers deletion (#1454)
1 parent 2bfca39 commit 236d7a0

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
set check_function_bodies = off;
2+
3+
CREATE OR REPLACE FUNCTION public.send_account_transfers_delete_temporal_activity()
4+
RETURNS trigger
5+
LANGUAGE plpgsql
6+
SECURITY DEFINER
7+
AS $function$
8+
declare
9+
paymaster bytea = '\xb1b01dc21a6537af7f9a46c76276b14fd7ceac67'::bytea;
10+
workflow_ids text[];
11+
begin
12+
-- Check if it's from or to paymaster
13+
if (NEW.f is not null and NEW.f = paymaster) or
14+
(NEW.t is not null and NEW.t = paymaster) then
15+
return NEW;
16+
end if;
17+
-- Only proceed with deletions if we have workflow IDs
18+
delete from public.activity a
19+
where a.event_name = 'temporal_send_account_transfers'
20+
and a.event_id in (select t_sat.workflow_id
21+
from temporal.send_account_transfers t_sat
22+
where t_sat.created_at_block_num <= NEW.block_num
23+
and t_sat.status != 'failed');
24+
return NEW;
25+
end;
26+
$function$
27+
;
28+
29+

0 commit comments

Comments
 (0)