I am using supabase
and I try to implement some warning functionality. I want to send an E-Mail when a value drops under a specific value.
I know about database triggers
but I am not sure about two things.
Your design is possible.
About point 1:
postgres trigger-functions can see the OLD and NEW value as special variables. See here: https://www.postgresql.org/docs/current/plpgsql-trigger.html
They may be null though, depending on the operation (insert doesn't have a OLD, delete has no NEW). You can also access the operation that triggered your trigger using TG_OP
, see here: PostgreSQL: Checking for NEW and OLD in a function for a trigger
About point 2:
Postgres-triggers can make http-requests with the pg_net
-extension, which you can use to trigger your edge-function with the right data. It's a bit bare-bones, but it works. https://supabase.com/docs/guides/database/extensions/pg_net