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
| Name | Type | Description |
|---|---|---|
schema | string | The name of the schema (database) that contains the table |
table | string | The name of the table to write the records into |
match | []string | The columns whose values address an existing record, which have to name a unique index the table declares |
records | []Record | The records to write, each a key-value object carrying a value for every match column |
Outputs
| Name | Type | Description |
|---|---|---|
inserted | []string | The identifiers of the records the write created |
updated | []string | The identifiers of the records the write found and changed |
count | int | The 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 }}"