DocsWorkflowsComponentsAppapp:record:bulk:upsert

app:record:bulk:upsert

Writes a set of records into a schema table, addressing each by a business key rather than by an id. It exists so a workflow syncing anything stops carrying the 'did this row already exist' branch. Answering that in the document costs a read, a compare and two conditional writes, and every one of those steps is a chance for the two branches to drift apart. The database already knows, through the unique index the match names, so the step asks it.

Options

NameTypeDescription
schemastringThe name of the schema (database) that contains the table
tablestringThe name of the table to write the records into
match[]stringThe columns whose values address an existing record, which have to name a unique index the table declares
records[]RecordThe records to write, each a key-value object carrying a value for every match column

Outputs

NameTypeDescription
inserted[]stringThe identifiers of the records the write created
updated[]stringThe identifiers of the records the write found and changed
countintThe number of records the write reached, inserted and updated together

Example

name: Sync translations from an export
actions:
  - name: applied
    component: app:record:bulk:upsert
    vars:
      schema: translations
      table: translations
      match: [project_id, key_id, language, variant]
      records: "{{ writes.items }}"

outputs:
  inserted: "{{ applied.inserted }}"
  updated: "{{ applied.updated }}"