Chelabase
ManagementFunctions

Add a trigger to a function on the branch

POST
/v1/databases/{id}/branches/{branch_id}/functions/{name}/triggers

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
AuthorizationBearer <token>

In: header

Path Parameters

id*string

Database id

Formatuuid
branch_id*string

Branch id

Formatuuid
name*string

Function name

Request Body

application/json

TypeScript Definitions

Use the request body type in TypeScript.

bucket?|

storage only; every bucket when absent.

events*array<string>

table: insert, update, delete. storage: object.created, object.updated, object.deleted, object.moved. Each once, never mixed.

pg_database*string

The branch's Postgres database the table (or, for storage, the bucket's project) is in.

prefix?|

storage only; every key when absent.

schema?|

table only.

source*FunctionTriggerSource

Where a trigger's events come from.

Value in

  • "table"
  • "storage"
table?|

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"}