mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-16 01:44:03 +03:00
a66fb42ce2
* Separate DB and metadata migrations * Refactor Migrate.hs to generate list of migrations at compile-time * Replace ginger with shakespeare to improve performance * Improve migration log messages
36 lines
1.2 KiB
Plaintext
36 lines
1.2 KiB
Plaintext
CREATE OR REPLACE function hdb_views.#{qualifiedTriggerName}() RETURNS trigger
|
|
LANGUAGE plpgsql
|
|
AS $$
|
|
DECLARE
|
|
_old record;
|
|
_new record;
|
|
_data json;
|
|
BEGIN
|
|
IF TG_OP = 'UPDATE' THEN
|
|
_old := #{oldRow};
|
|
_new := #{newRow};
|
|
ELSE
|
|
/* initialize _old and _new with dummy values for INSERT and UPDATE events*/
|
|
_old := row((select 1));
|
|
_new := row((select 1));
|
|
END IF;
|
|
_data := json_build_object(
|
|
'old', #{oldPayloadExpression},
|
|
'new', #{newPayloadExpression}
|
|
);
|
|
BEGIN
|
|
IF (TG_OP <> 'UPDATE') OR (_old <> _new) THEN
|
|
PERFORM hdb_catalog.insert_event_log(CAST(TG_TABLE_SCHEMA AS text), CAST(TG_TABLE_NAME AS text), CAST('#{name}' AS text), TG_OP, _data);
|
|
END IF;
|
|
EXCEPTION WHEN undefined_function THEN
|
|
IF (TG_OP <> 'UPDATE') OR (_old *<> _new) THEN
|
|
PERFORM hdb_catalog.insert_event_log(CAST(TG_TABLE_SCHEMA AS text), CAST(TG_TABLE_NAME AS text), CAST('#{name}' AS text), TG_OP, _data);
|
|
END IF;
|
|
END;
|
|
|
|
RETURN NULL;
|
|
END;
|
|
$$;
|
|
DROP TRIGGER IF EXISTS #{qualifiedTriggerName} ON #{qualifiedTable};
|
|
CREATE TRIGGER #{qualifiedTriggerName} AFTER #{operation} ON #{qualifiedTable} FOR EACH ROW EXECUTE PROCEDURE hdb_views.#{qualifiedTriggerName}();
|