D109 · A batch action is one Postgres function per module, with a check-only mode, and a refused save raises one key that lists every refused row
Proposed · 2026-11-24 · zuki, in the #722 session, when the design system's import dialog was drafted · Answers #752; it binds when this page's pull request is merged · Applies to every module that adds or changes many records at once, first vehicles (#746); follows D3 and D10
Decision: A batch action, one that adds or changes many records at once such as a CSV import, is one Postgres function per module: <module>_batch(rows jsonb, check_only boolean default true), called by RPC under the user's session. It runs the same checks as the module's single-record function, through one check that both functions share, and adds the checks only a batch has, such as duplicates inside the batch and a row limit.
- Check-only mode writes nothing and returns
{ refusals: [{ row, field, key }] }.rowis the record's index in the array sent, from 0.fieldis the column the refusal names in its detail, asvehicle.field_requireddoes, or null when its key names none (such asvehicle.vin_taken) or the refusal is about the whole row.keyis the key the single-record function would raise for that row. An empty list means every row can be saved. A check is a question, not a refused action, so it returns and doesn't raise. - Save mode writes every row in one transaction and returns
{ created: [uuid] }. If any row is refused, nothing is written and the function raises one key,<module>.batch_refused, whose detail is the same{ refusals: [...] }list. - apps/web checks in the browser only what an input checks by itself: required, a whole number, a minimum and maximum, a value from the list. It turns each row's key into text with the same mapper it uses for one record, and the design system's import dialog shows the text on that row's cell.
Why: zuki wants batch import in many modules, starting with vehicles (#746). apps/web has no validation library, and its single-record forms check nothing beyond their inputs' own attributes: Postgres checks every field and refuses with a key and the field's name (D3, D10). Copying those checks into TypeScript for a batch would give the rules a second home, which D3 forbids. One function shape lets the design system's import dialog serve every module with no module code in it: a module passes its columns, a check and a save. Sharing one check between the single and batch functions keeps the two from drifting. Raising one key for a refused save keeps D10 whole, since every refused action still raises one stable key, while its detail still names every row.
Not taken: a save that returns its refusals instead of raising (it would make a refused save the one action in v2 that doesn't raise). A batch that saves the good rows and reports the others (zuki chose all or nothing, 2026-11-24). Checks in the browser with a schema library (a second home for the rules).
Consequences:
- Rules. Each module's batch gets rules with IDs before its tests (D27), in its rule page: the columns a row holds, the row limit, duplicates inside the batch, and
<module>.batch_refused. Vehicles' rules come with #746. - Backend. Each batch function gets pgTAP tests per rule ID (D19): check-only mode writes nothing, a refused save writes nothing and raises
<module>.batch_refusedwith every refused row, duplicates inside the batch, and each single-record refusal by row and field. The single-record function moves its checks into the shared check in the same change. Vehicles: #751. - Keys.
<module>.batch_refusedand each batch-only key (such as<module>.batch_duplicateand<module>.batch_too_many) get a line in the module's Interface section and text in both languages, as D10 says. - Frontend. The server action calls the function, catches
<module>.batch_refusedand returns its refusals to the dialog as{ row, field, message }.lib/errors/map.tsgains a reader for that refusals list, which the first batch slice's FE work builds; today it returns only a key and its text. The dialog is the design system'scsv-import-dialog.tsx, which arrives with the design system's 2.3.0 import (D88); a batch page waits for that import. - Activity log. A saved batch is one entry that opens to every row, as D52 says for an action that changes many rows.