cardinal

Metadata and schema

cardinal_meta compiles RecTypes and checks Records. cardinal_schema plans DDL. cardinal_naming names new Records.

cardinal_meta

Elixir reads an app's RecType YAML and permission files and passes their text to cardinal_meta. The crate returns compiled metadata.

Read. Parse RecType YAML v1 against the registry of 44 field types.

Validate. Run Frappe's DocType validation rules. Where Frappe would quietly fix a definition, Cardinal refuses it. Errors name the file and a path such as fields[4].options.

Compile. Merge the site's Custom Fields, Property Setters and Custom RecPerm rows into a TenantMeta: tables and columns, the layout tree, links and the fetch plan, compiled expressions, defaults and permission rules.

Hash. Compute a hash that YAML style and key order do not change.

The same crate checks Records around their controller hooks:

StepChecks
PrepareCasts to wire forms, fills defaults, applies read_only_depends_on, resolves link fetches
ValidateMandatory, Select options, length, ranges, rounding, set_only_once, update after submit, URL schemes, email and phone values
CopyThe Record a Duplicate starts from
DiffThe Version rows a save writes

It also builds the desk meta bundle (layout, field UI, list config, indicators), lists the Link fields that point at a RecType for delete checks, and types filter values for cardinal_query. With the html feature, the server build also sanitizes Text Editor and HTML Editor values and print pages. The WASM build leaves that out.

cardinal_schema

plan compares a site's compiled RecTypes with a snapshot of its Postgres catalog and returns the DDL that brings every rt_ and ct_ table up to date.

PlannedNever planned
Create a tableDrop a table
Add a columnDrop a column
Widen a number column, or any column to textNarrow a type
Create an autoincrement sequence
Create or drop a unique index, create an index

A column whose type would have to narrow is an error that names it. cardinal schema orphans lists columns a RecType no longer has. Every identifier is quoted. SchemaService reads the catalog and runs each statement in the site's transaction.

cardinal_naming

new_name reads a RecType's autoname:

autonameName
autoincrementThe table sequence's next value
UUIDA UUIDv7
field:customer_nameThat field's value, trimmed and checked
promptThe name the user typed
INV-.YYYY.-.####, naming_series:, format:{...}A series, with date parts in the system zone
hash, or noneTen base32hex characters

An amended Record gets <source>-1, or the source's -N counted on. Between those rules, Record Naming Rules and controllers' autoname hooks run in Elixir.

When a name needs a series counter or a sequence value, the crate returns a request and NamingService calls again with the answer. The clock, 10 random bytes and the zone come in as arguments.

On this page