From 53b25e1656ce7f3edbeae068a1084b19d4d4d22c Mon Sep 17 00:00:00 2001 From: xbgmsharp Date: Wed, 4 Oct 2023 16:40:45 +0200 Subject: [PATCH] Add public.delete_vessel_fn, delete all data received from a vessel --- initdb/02_3_2_signalk_public_functions.sql | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/initdb/02_3_2_signalk_public_functions.sql b/initdb/02_3_2_signalk_public_functions.sql index ff29f96..9983d41 100644 --- a/initdb/02_3_2_signalk_public_functions.sql +++ b/initdb/02_3_2_signalk_public_functions.sql @@ -1434,3 +1434,17 @@ BEGIN select * from auth.accounts a where email = _email; END $dump_account$ language plpgsql security definer; + +CREATE OR REPLACE FUNCTION public.delete_vessel_fn(IN _vessel_id TEXT) RETURNS BOOLEAN +AS $delete_account$ +BEGIN + select count(*) from api.metrics m where vessel_id = _vessel_id; + delete from api.metrics m where vessel_id = _vessel_id; + select * from api.metadata m where vessel_id = _vessel_id; + delete from api.logbook l where vessel_id = _vessel_id; + delete from api.moorages m where vessel_id = _vessel_id; + delete from api.stays s where vessel_id = _vessel_id; + delete from api.metadata m where vessel_id = _vessel_id; + RETURN True; +END +$delete_account$ language plpgsql security definer; \ No newline at end of file