diff --git a/etc/db/database-template.sql b/etc/db/database-template.sql index f9230c2..7cec03c 100644 --- a/etc/db/database-template.sql +++ b/etc/db/database-template.sql @@ -153,15 +153,23 @@ CREATE FUNCTION public.notify() RETURNS trigger AS $$ DECLARE channel text := TG_ARGV[0]; +payload text; BEGIN -PERFORM pg_notify(channel, json_build_object( +payload := 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); +)::text; + +IF octet_length(payload) < 8000 THEN +PERFORM pg_notify(channel, payload); +ELSE +-- We need to find another solution +RAISE INFO 'Payload over limit'; +END IF; RETURN NULL; END; $$; @@ -193,7 +201,8 @@ SET default_table_access_method = heap; CREATE TABLE public.projects ( pid text NOT NULL, name text NOT NULL, - schema text NOT NULL + schema text NOT NULL, + meta jsonb DEFAULT '{}'::jsonb NOT NULL );