Skip to content

A full-featured CRM built with React, shadcn/ui, and Supabase.

Fix(contact): Update last_seen when a note is added to the contact

Jonathan ARNAULT8922243da1fc
diff --git a/supabase/migrations/20240809135136_trigger_contact_note.sql b/supabase/migrations/20240809135136_trigger_contact_note.sql
new file mode 100644
index 00000000..8ff4505e
--- /dev/null
+++ b/supabase/migrations/20240809135136_trigger_contact_note.sql
@@ -0,0 +1,19 @@
+create function public.trigger_contactNotes_created()
+returns trigger
+language plpgsql
+security definer set search_path = ''
+as $$
+begin
+ update public."contacts"
+ set
+ last_seen = new.date
+ where id = new.contact_id;
+
+ return new;
+end;
+$$;
+
+create or replace trigger trigger_contactNotes_created
+ after insert or update or delete on "contactNotes"
+ for each row
+ execute function trigger_contactNotes_created();