Index RecTypes
Tables of derived rows an app rebuilds from other records, written only by Cardinal.DB.replace_rows.
An index RecType holds rows an app computes from other records, such as Eden's graph of which record links to which. Rows have no lifecycle, no Version and no link check. Only Cardinal.DB.replace_rows/4 writes them.
Declare one
Set index: true. Fields must hold plain values. Keep record names in Data fields, since a Link would block the target's delete.
schema: 1
name: Eden Link
module: Eden
index: true
ai: false
indexes:
- {fields: [src_rectype, src_name]}
- {fields: [dst_rectype, dst_name]}
fields:
- {fieldname: src_rectype, fieldtype: Data, label: From RecType}
- {fieldname: src_name, fieldtype: Data, label: From}
- {fieldname: field, fieldtype: Data, label: Field}
- {fieldname: kind, fieldtype: Select, label: Kind, options: "link\nflow"}
- {fieldname: dst_rectype, fieldtype: Data, label: To RecType}
- {fieldname: dst_name, fieldtype: Data, label: To}These keys fail the build on an index RecType: istable, issingle, is_submittable, is_tree, virtual, track_changes, allow_rename, has_web_view, allow_web_form, system_manager_only, and any autoname other than hash.
Write rows
replace_rows(ctx, rectype, match, rows) deletes the rows whose fields equal match and inserts rows in their place. It needs an as_system ctx and runs in the caller's transaction.
def replace(%Ctx{} = ctx, rectype, name, rows) do
DB.replace_rows(
DB.as_system(ctx),
"Eden Link",
%{"src_rectype" => rectype, "src_name" => name},
rows
)
endIt returns {:ok, count}. Eden calls it in the transaction that saves the source record, so the index and the record commit together. One call takes at most 5,000 rows.
Read rows
Read with Cardinal.DB.get_list/3 as usual. Every other record call (insert, save, delete) refuses an index RecType.
Eden Link gives no role read access, so Eden reads it as the system and then checks each record it found as the user. Do the same when an index spans records with different permissions.