Add a trigger
Goal
Create a public.triggers row so a record event (item_created, item_updated, …) dispatches a pipeline execution.
Prerequisites
- The
system_adminrole — trigger mutations are second-surface gated (decision0026, migration081); account members read but cannot write. - The pipeline the trigger will point at (Add a pipeline).
INTERNAL_INVOKE_SECRETset on the deployed functions — dispatch POSTs topipeline-runner-backgroundwith anX-Internal-Secretheader and logscannot dispatch trigger pipeline(then silently no-ops) when it is unset (.framework/functions/_shared/trigger-engine.ts). See Environment variables.
Steps
- Pick the
event_type. Snake_case<entity>_<verb>— the engine'sEventTypeunion coversitem,account,person,thread,message,attachment, andlink×created/updated/deleted(.framework/functions/_shared/trigger-engine.ts). Useitem_created, notitem.created— the admin UI's own placeholder text (e.g., item.created) is misleading (.framework/src/pages/admin/TriggerDetailPage.tsx). Scheduled and webhook entry points are not trigger event types — use a timer or an inbound webhook for those. Add filter config (optional).
config.entity_typescopes the row to one table;config.type_slugscopes it to one type (resolved fromtype_idwhen the record carries only that);config.filterssupports$eq,$ne,$gt,$gte,$lt,$lte,$in,$nin,$existsondata->>'field'paths; andconfig.fire_on_transitionfires only when the record moves into a matching state (.framework/functions/_shared/trigger-engine.ts).{ "name": "New ticket", "event_type": "item_created", "pipeline_id": "<pipeline-uuid>", "config": { "entity_type": "items", "type_slug": "ticket" } }- Create the trigger. Admin UI → Configs → Triggers → New, or
POST /api/triggers—name,event_type, andpipeline_idrequired (.framework/functions/triggers.ts). - Keep it enabled.
is_active: true(default). Only active triggers are matched on an event;?action=toggleflips it (.framework/functions/triggers.ts). Deleting a trigger is a soft delete (is_active = false) — execution history survives.
Verify
- Create or update a matching record via
/api/admin-data— creates and updates callfireCreateTriggers/fireUpdateTriggersafter the write (.framework/functions/admin-data.ts). - A
pipeline_executionsrow appears inqueued, thenrunning/completedaspipeline-runner-backgroundpicks it up — watch Observability → Executions. - The
record_trigger_fireRPC bumpstriggers.trigger_count/last_triggered, andtrigger.fired/trigger.failedaudit rows land inpublic.logs.
Common mistakes
- Dotted event names.
item.createdmatches nothing — event names areitem_createdetc. - Expecting
item_deleted. The enum includes it, but theadmin-datadelete path never invokesfireDeleteTriggers— only create and update fire (.framework/functions/admin-data.ts;.framework/functions/_shared/trigger-engine.ts). Use an update (is_active = false) if you need delete-like notification. - Missing
INTERNAL_INVOKE_SECRET. The trigger inserts the queued execution row, but the dispatch topipeline-runner-backgroundcannot be authenticated, so nothing runs — check function logs for theINTERNAL_INVOKE_SECRET not seterror. - Filtering on
type_slugwithout realizing the resolution. Records carrytype_id, not the slug; the engine resolves the slug once per event when any trigger filters onconfig.type_slug(.framework/functions/_shared/trigger-engine.ts).