Skip to content

Database Schema

The D1 database uses 10 tables. The migration is at src/db/migrations/0001_init.sql.

Every entity in the system.

ColumnTypeNotes
idTEXT PKlat_<prefix>_<nanoid>
typeTEXT NOT NULLCHECK constraint on 7 valid types
parent_idTEXTFK to entities(id), nullable for root
nameTEXT NOT NULLDisplay name
statusTEXT NOT NULLDefault 'active'
tagsTEXTJSON array, default '[]'
extensionTEXTJSON, type-specific data, default '{}'
telos_problemsTEXTJSON array, default '[]'
telos_missionTEXTNullable
versionINTEGER NOT NULLDefault 1, incremented on every update
created_atTEXT NOT NULLISO 8601
updated_atTEXT NOT NULLISO 8601

Indexes: type, parent_id, status.

Immutable event log.

ColumnTypeNotes
idTEXT PKevt_<nanoid>
typeTEXT NOT NULLEvent type string
entity_idTEXT NOT NULLFK to entities(id) CASCADE
timestampTEXT NOT NULLISO 8601
dataTEXTJSON, default '{}'
seqINTEGER NOT NULLMonotonic sequence number

Indexes: entity_id, seq, type.

Singleton row for atomic sequence generation.

ColumnTypeNotes
idINTEGER PKCHECK(id = 1), always exactly one row
current_seqINTEGER NOT NULLDefault 0

Access control rules.

ColumnTypeNotes
idTEXT PKPolicy identifier
subjectTEXT NOT NULLEntity ID or role pattern
actionTEXT NOT NULLread, write, execute
objectTEXT NOT NULLEntity ID or * wildcard
conditionTEXTJSON condition object, default '{}'
effectTEXT NOT NULLallow or deny
created_atTEXT NOT NULLISO 8601

Indexes: subject, object.

Event subscription registrations (Phase 1: poll-only).

ColumnTypeNotes
idTEXT PKSubscription identifier
subscriber_idTEXT NOT NULLWho is subscribing
source_entity_idTEXT NOT NULLFK to entities(id) CASCADE
event_filterTEXTJSON filter config, default '{}'
delivery_methodTEXT NOT NULLDefault 'poll'
created_atTEXT NOT NULLISO 8601

Indexes: source_entity_id, subscriber_id.

Queryable goal records with status, target dates, and goal hierarchy.

Obstacles with severity levels and cross-references to goals.

Strategic approaches linking challenges to goals.

Quantitative measurements with direction and targets.

Actionable tasks with assignees, priority, and Kanban status.

Financial allocations and spend tracking per category and period.

Join table mapping entities to their team members with roles. Composite PK on (entity_id, member_entity_id).

Flexible JSON storage for telos fields that do not need SQL querying. Composite PK on (entity_id, field). Valid fields: narratives, projects, journal, ideas, beliefs, skills, documentation, sops, logs.

All telos tables have entity_id foreign keys with ON DELETE CASCADE and indexes on entity_id.