name: fantasia-template-custom-fields description: >- Document template custom fields: field definitions, document values, merge-at-read, orphan retention, and template editor flows. Use when designing or implementing template fields, document forms, related SQLite schema, or projectContent IPC.
Document template custom fields
Canonical documentation
- Design (not yet in v4 schema): docs/database/templateCustomFields.md
- Shipped schema: docs/database/projectDB.md — same commit when migrations/IPC land
- Index: docs/database/README.md
Related skills
- fantasia-worldbuilding-domain
- fantasia-sqlite-main
- fantasia-electron-preload
- fantasia-action-manager
Rule
fa-template-custom-fields.mdc when touching design or implementation.
Design summary
- Template shell — existing
document_templates - Field definitions — planned
template_fields(UUIDfield_id, soft-delete, sort, type, config) - Document values — planned
document_field_values+ field-scoped link tables - Orphans — values for inactive/removed defs stay in DB; UI shows active fields only
- Read — active defs + all values; bind by
field_id - Save — validate active defs; upsert; never auto-delete orphans
Implementation phases (short)
- Schema v5+ — DDL + migrate wiring → projectDB.md
- Main persist —
projectDbContent/* - Zod —
src-electron/shared/faProjectTemplateField*,faProjectDocumentField* - IPC + preload — bridge +
projectContentAPI.ts - Types —
types/I_faProject*Domain.ts - Renderer — Pinia, document editor merge/save
- Template editor UI — field CRUD, type-change guards
- Deferred — orphan recovery UI, cross-field search, version pins
Do not
- Hard-delete document values when field removed from template
- Key values by label/slug/sort order —
field_idonly - Silently change field type + coerce values
- Ship template versioning / per-document version pins in v1
- Store custom field data in
electron-storeorproject_dataKV
Types
Shared types → types/. See types-folder.mdc.