mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 17:31:56 +03:00
27 lines
992 B
Django/Jinja
27 lines
992 B
Django/Jinja
CREATE OR REPLACE function hdb_views.notify_hasura_{{NAME}}_{{OPERATION}}() RETURNS trigger
|
|
LANGUAGE plpgsql
|
|
AS $$
|
|
DECLARE
|
|
payload json;
|
|
_data json;
|
|
id text;
|
|
BEGIN
|
|
id := gen_random_uuid();
|
|
_data := json_build_object(
|
|
'old', {{OLD_DATA_EXPRESSION}},
|
|
'new', {{NEW_DATA_EXPRESSION}}
|
|
);
|
|
payload := json_build_object(
|
|
'op', TG_OP,
|
|
'data', _data
|
|
)::text;
|
|
INSERT INTO
|
|
hdb_catalog.event_log (id, schema_name, table_name, trigger_name, trigger_id, payload)
|
|
VALUES
|
|
(id, TG_TABLE_SCHEMA, TG_TABLE_NAME, '{{NAME}}', '{{ID}}', payload);
|
|
RETURN NULL;
|
|
END;
|
|
$$;
|
|
DROP TRIGGER IF EXISTS notify_hasura_{{NAME}}_{{OPERATION}} ON {{SCHEMA_NAME}}.{{TABLE_NAME}};
|
|
CREATE TRIGGER notify_hasura_{{NAME}}_{{OPERATION}} AFTER {{OPERATION}} ON {{SCHEMA_NAME}}.{{TABLE_NAME}} FOR EACH ROW EXECUTE PROCEDURE hdb_views.notify_hasura_{{NAME}}_{{OPERATION}}();
|