Add a type
Goal
Create a public.types row whose design_schema drives validation, permissions, and the generic list/detail UI for a new record shape. Records created through /api/admin-data stamp this schema onto themselves at write time, so a broken schema propagates into every record.
Prerequisites
- A
system_adminlogin or an API key with*:*scope —POST /api/typesthrowsSystem admin requiredfor anyone else (.framework/functions/types.ts). - The target
kinddecided up front (item,thread,message,link,attachment,watcher,person,account). The kind chooses the runtime table and cannot be implied later — see Runtime records.
Steps
Draft the
design_schema. Work through the checklist in Design schema; the field/display enums are in Design schema reference. The schema below is the minimum for the generic renderer:{ "scope": "account", "fields": { "title": { "data_type": "text", "label": "Title", "required": true, "system": true }, "status": { "data_type": "select", "label": "Status", "required": true, "system": true, "options": ["open", "closed"] } }, "views": { "default_list": { "type": "list", "display": "table", "label": "Tickets", "fields": { "title": { "sortable": true, "display_type": "text" }, "status": { "sortable": true, "display_type": "badge" }, "created_at": { "sortable": true, "display_type": "timestamp" } }, "default_sort": { "field": "created_at", "direction": "desc" } }, "default_detail": { "type": "detail", "label": "Ticket", "sections": [ { "title": "Core", "fields": { "title": { "display_type": "input" }, "status": { "display_type": "select" } } } ] } }, "record_permissions": { "system_admin": ["create", "read", "update", "delete"], "support": ["create", "read", "update"] }, "functionality": null }fields: every entry needsdata_type,label,required.select,multiselect, andradioneedoptions—generateValidationSchemaderives allowed values from them (.framework/functions/_shared/schema-utils.ts).record_permissionskeys areroles.slugvalues matched verbatim —system_admin, notsystem-admin. A misspelled or nonexistent slug silently grants nothing (.framework/functions/_shared/permissions.ts).- Reserved column names.
itemshas real columnstitle,description, andstatus— a field with one of those names andsystem: truemaps onto the column; the same name withsystem: falselands inrecord.dataand list/detail views show the column's value (e.g. lifecycleactive) instead of yours. Picksystem: truefor these names or rename the field. record_permissionsis the base, most restrictive grant; addfields.*.permissionsonly to loosen one field or to restrict asystem: truefield — see Permission model.- Generic apps (
renderer: "generic") needviews.default_listandviews.default_detailreferencing real fields with knowndisplay_typevalues; custom apps can omit views but still needfields+record_permissionssoadmin-datacan stamp and validate.
Create the type. Either:
- Admin UI → Configs → Types → New (
configs/types/new), fill in name, slug, kind, and paste the schema into the Design Schema JSON field — the page POSTs to/api/types?action=create(.framework/src/pages/admin/TypeDetailPage.tsx). - API:
POST /api/typeswith a body containingname,slug,kind, anddesign_schema— all three fields are required (.framework/functions/types.ts).
- Admin UI → Configs → Types → New (
- Let the API generate
validation_schema. Do not send it yourself — the create handler replaces a missingvalidation_schemawithgenerateValidationSchema(design_schema)before insert, and update regenerates it wheneverdesign_schemachanges (.framework/functions/types.ts). - Set the row-level fields.
ownership(system/app/tenant),is_active,icon,color, and optionalapp_idare columns on thetypesrow, not insidedesign_schema.
Verify
GET /api/types?action=get&slug=<slug>&include_schema=truereturns the row with a non-nullvalidation_schema.- Create a record:
POST /api/admin-data?action=createwith{ "entity": "items", "type_slug": "<slug>", "title": "…", "data": {…} }— the stored record carries the stampeddesign_schema. - If the app uses the generic renderer, open its list page — an unknown
display_typeor missingdefault_listview shows up immediately as a broken page.
Common mistakes
- Slug collisions. Slugs must be unique per
kind(.framework/migrations/015_types_kind_slug_unique.sql); create throwsType with slug '<slug>' already exists for kind '<kind>'. App-install seeds go further —conflict: "kind,slug"makes type slugs effectively global, so prefix app types (support_ticket, notticket) — see Seeds. system-adminvssystem_admin. Seeded role slugs use underscores;system-admingrants nothing.- Editing
data_typeon a live field. Existing records keep their old stored values; the schema change does not migrate data. - Using
generateto scaffold types.npx spine-framework generateemits a stale legacy schema shape — author via the admin UI or/api/types(see Build your first app — Gaps).