From 0cdff4c493967528744268c331fe88acc0051595 Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Thu, 3 Sep 2020 13:59:51 +0200 Subject: [PATCH] Add notification trigger function to DB --- etc/db/database-template.sql | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/etc/db/database-template.sql b/etc/db/database-template.sql index 81af8b6..98499cb 100644 --- a/etc/db/database-template.sql +++ b/etc/db/database-template.sql @@ -144,6 +144,31 @@ CREATE EXTENSION IF NOT EXISTS postgis_topology WITH SCHEMA topology; COMMENT ON EXTENSION postgis_topology IS 'PostGIS topology spatial types and functions'; +-- +-- Name: notify(); Type: FUNCTION; Schema: public; Owner: postgres +-- + +CREATE FUNCTION public.notify() RETURNS trigger + LANGUAGE plpgsql + AS $$ +DECLARE +channel text := TG_ARGV[0]; +BEGIN +PERFORM pg_notify(channel, json_build_object( +'tstamp', CURRENT_TIMESTAMP, +'operation', TG_OP, +'schema', TG_TABLE_SCHEMA, +'table', TG_TABLE_NAME, +'old', row_to_json(OLD), +'new', row_to_json(NEW) +)::text); +RETURN NULL; +END; +$$; + + +ALTER FUNCTION public.notify() OWNER TO postgres; + -- -- Name: set_survey(text); Type: PROCEDURE; Schema: public; Owner: postgres --