Add a trigger to a function on the branch
A table trigger is installed in the branch's database by the worker (pending_install, then installed or failed); each committed matching row change is then POSTed to the function's fetch handler with header chelabase-event: db and body {id, type, schema, table, record, old_record, txid} (over 256 KiB: record and old_record null, truncated: true and primary_key). Delivery is at least once (dedupe on id): a non-2xx answer is retried with backoff, and the 10th failure makes the event dead (dead_count). Events queue while the function is disabled; a pending event is never dropped, and dead events past 10,000 per database or 7 days are removed and counted (dropped_count). The database's compute stays awake while it has an installed table trigger. A storage trigger starts installed. A new branch inherits the triggers.
Authorization
bearer In: header
Path Parameters
Database id
uuidBranch id
uuidFunction name
Request Body
application/json
TypeScript Definitions
Use the request body type in TypeScript.
storage only; every bucket when absent.
table: insert, update, delete. storage: object.created, object.updated,
object.deleted, object.moved. Each once, never mixed.
The branch's Postgres database the table (or, for storage, the bucket's project) is in.
storage only; every key when absent.
table only.
Where a trigger's events come from.
Value in
- "table"
- "storage"
table only.
Response Body
application/json
application/json
application/json
application/json
application/json
application/json
application/json
application/json
curl -X POST "https://example.com/v1/databases/497f6eca-6276-4993-bfeb-53cbbbba6f08/branches/497f6eca-6276-4993-bfeb-53cbbbba6f08/functions/string/triggers" \ -H "Content-Type: application/json" \ -d '{ "events": [ "string" ], "pg_database": "string", "source": "table" }'{ "bucket": "string", "dead_count": 0, "dropped_count": 0, "enabled": true, "events": [ "string" ], "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "last_delivered_at": "2019-08-24T14:15:22Z", "last_delivery_error": "string", "last_error": "string", "pg_database": "string", "prefix": "string", "schema": "string", "source": "table", "state": "string", "table": "string"}