Перейти к основному содержимому

Table Definitions

Full column specifications for all tables in the orchestrator schema.

users

ColumnTypeConstraintsDescription
idUUIDPKUser identifier
subjectTEXTNOT NULL, UNIQUEAuth provider subject (Firebase UID or dev token)
emailTEXTNOT NULLUser email
nicknameTEXTNOT NULL, default ''Display nickname
nameTEXTNOT NULL, default ''First name
surnameTEXTNOT NULL, default ''Last name
avatar_urlTEXTNULLProfile avatar URL
country_codeTEXTNULLISO country code
date_of_birthTIMESTAMPTZNULLDate of birth
is_bannedBOOLEANNOT NULL, default falseBan flag
has_agreed_with_termsBOOLEANNOT NULL, default falseTerms acceptance
has_agreed_with_privacy_policyBOOLEANNOT NULL, default falsePrivacy acceptance
created_atTIMESTAMPTZNOT NULLCreation timestamp
updated_atTIMESTAMPTZNOT NULLLast update timestamp
deleted_atTIMESTAMPTZNULLSoft delete timestamp

Indexes: idx_users_subject on subject


user_preferences

ColumnTypeConstraintsDescription
user_idUUIDPK, FK -> users(id) CASCADEUser reference
platform_themeTEXTNULLUI theme preference
platform_languageTEXTNULLLanguage code
currency_codeTEXTNULLPreferred currency
updated_atTIMESTAMPTZNOT NULLLast update timestamp

user_push_tokens

ColumnTypeConstraintsDescription
user_idUUIDPK, FK -> users(id) CASCADEUser reference
push_tokenTEXTNOT NULLFCM token
updated_atTIMESTAMPTZNOT NULLLast update timestamp

workspaces

ColumnTypeConstraintsDescription
idUUIDPKWorkspace identifier
user_idUUIDNOT NULL, FK -> users(id) CASCADEOwner
nameTEXTNOT NULLWorkspace display name
created_atTIMESTAMPTZNOT NULLCreation timestamp
updated_atTIMESTAMPTZNOT NULLLast update timestamp

Indexes: idx_workspaces_user_id on user_id

Runtime status comes from UserSwarm.status in Kubernetes, not this table.


agents

ColumnTypeConstraintsDescription
idUUIDPKAgent identifier
workspace_idUUIDNOT NULL, FK -> workspaces(id) CASCADEParent workspace
nameTEXTNOT NULLAgent display name
slugTEXTNOT NULLURL-safe identifier (e.g., wally, manager)
roleTEXTNOT NULLAgent role (e.g., default)
descriptionTEXTNOT NULL, default ''Agent description
avatar_urlTEXTNOT NULL, default ''Agent avatar
sort_orderINTEGERNOT NULL, default 0Display order
created_atTIMESTAMPTZNOT NULLCreation timestamp
updated_atTIMESTAMPTZNOT NULLLast update timestamp

Indexes: idx_agents_workspace_slug UNIQUE on (workspace_id, slug), idx_agents_workspace_id on workspace_id


conversations

ColumnTypeConstraintsDescription
idUUIDPKConversation identifier
workspace_idUUIDNOT NULL, FK -> workspaces(id) CASCADEParent workspace
agent_idUUIDNULL, FK -> agents(id) SET NULLAssociated agent
typeTEXTNOT NULLConversation type
titleTEXTNOT NULLConversation title
unread_countINTEGERNOT NULL, default 0Unread message count
created_atTIMESTAMPTZNOT NULLCreation timestamp
updated_atTIMESTAMPTZNOT NULLLast update timestamp

Indexes: idx_conversations_workspace_id on workspace_id, idx_conversations_workspace_type on (workspace_id, type)


messages

ColumnTypeConstraintsDescription
idUUIDPKMessage identifier
conversation_idUUIDNOT NULL, FK -> conversations(id) CASCADEParent conversation
roleTEXTNOT NULLMessage role (user, assistant, system)
contentJSONBNOT NULLMessage content (structured)
statusTEXTNOT NULLMessage status
local_idTEXTNULLClient-generated ID for deduplication
agent_idUUIDNULL, FK -> agents(id) SET NULLAgent that sent/received
attachmentsJSONBNOT NULL, default '[]'File attachments
created_atTIMESTAMPTZNOT NULLCreation timestamp
updated_atTIMESTAMPTZNOT NULLLast update timestamp

Indexes: idx_messages_conversation_created_at on (conversation_id, created_at DESC, id DESC), idx_messages_local_id on local_id


mcp_audit_logs

Audit log for every MCP tool call made by Agent Runtime pods. Writes are async (goroutine with 5s timeout) to avoid response latency. Required for ISO 27001 compliance.

ColumnTypeConstraintsDescription
idUUIDPKAudit log identifier
user_idTEXTNOT NULLUser who triggered the tool call
workspace_idTEXTNOT NULLWorkspace context
session_idTEXTNULLMCP session identifier
tool_nameTEXTNOT NULLMCP tool name (e.g., send_push_notification)
inputJSONBNOT NULLTool call input parameters
outputJSONBNULLTool call output
api_callsJSONBNULLExternal API calls made during execution
successBOOLEANNOT NULLWhether the tool call succeeded
error_messageTEXTNULLError message on failure
duration_msINTEGERNOT NULLExecution time in milliseconds
remote_addrTEXTNULLCalling pod's IP address
created_atTIMESTAMPTZNOT NULLTimestamp of the tool call

tools

Global tool catalog. Seeded from migrations/orchestrator/seed/tools.json on startup.

ColumnTypeConstraintsDescription
nameTEXTPKTool identifier
display_nameTEXTNOT NULLHuman-readable name
descriptionTEXTNOT NULLTool description
categoryTEXTNOT NULLCategory grouping
icon_urlTEXTNOT NULLTool icon URL
sort_orderINTEGERNOT NULLDisplay order
created_atTIMESTAMPTZNOT NULLCreation timestamp

agent_settings

Per-agent model and response configuration. One row per agent.

ColumnTypeConstraintsDescription
agent_idUUIDPK, FK -> agents(id) CASCADEAgent reference
modelTEXTNOT NULL, default 'auto'LLM model selection
response_lengthTEXTNOT NULL, default 'auto'Response length preference
allowed_toolsTEXT[]NOT NULL, default '{}'Tools this agent can use
created_atTIMESTAMPTZNOT NULLCreation timestamp
updated_atTIMESTAMPTZNOT NULLLast update timestamp

agent_prompts

System prompt templates per agent.

ColumnTypeConstraintsDescription
idUUIDPKPrompt identifier
agent_idUUIDNOT NULL, FK -> agents(id) CASCADEAgent reference
nameTEXTNOT NULLPrompt display name
descriptionTEXTNOT NULLPrompt description
contentTEXTNOT NULLSystem prompt text
sort_orderINTEGERNOT NULLDisplay order
created_atTIMESTAMPTZNOT NULLCreation timestamp
updated_atTIMESTAMPTZNOT NULLLast update timestamp

Indexes: idx_agent_prompts_agent_id on agent_id


agent_history

Manager-created conversation history summaries for an agent.

ColumnTypeConstraintsDescription
idUUIDPKHistory entry identifier
agent_idUUIDNOT NULL, FK -> agents(id) CASCADEAgent reference
conversation_idUUIDNULL, FK -> conversations(id) SET NULLAssociated conversation
titleTEXTNOT NULLHistory entry title
subtitleTEXTNOT NULLHistory entry subtitle
created_atTIMESTAMPTZNOT NULLCreation timestamp

Indexes: idx_agent_history_agent_id on (agent_id, created_at DESC)


memory_drawers

Core vector store for the MemPalace memory system. Each drawer is a chunk of verbatim content with a pgvector embedding for semantic search. See the MemPalace Memory Pipeline for the full state machine and processing flow.

ColumnTypeConstraintsDescription
idTEXTPKMD5-based deterministic identifier
workspace_idUUIDNOT NULLWorkspace scope
wingTEXTNOT NULLTop-level topic category
roomTEXTNOT NULLSubtopic within the wing
hallTEXTNOT NULL, default ''Optional granular grouping
contentTEXTNOT NULLVerbatim memory text
embeddingvector(1536)NULLpgvector embedding for semantic search
importanceREALNOT NULL, default 3.0Priority score (0.0–5.0)
memory_typeTEXTNOT NULL, default ''Classified type: decision, preference, milestone, problem, emotional, fact, task
source_fileTEXTNOT NULL, default ''Origin file reference
added_byTEXTNOT NULL, default 'system'Who stored it (e.g., auto-ingest, mobile, agent name)
added_by_agentTEXTNOT NULL, default ''Agent UUID for affinity ranking
stateTEXTNOT NULL, default 'raw'Pipeline state: raw, processed, merged, failed
summaryTEXTNOT NULL, default ''LLM-generated one-line summary
last_accessed_atTIMESTAMPTZNULLUpdated on retrieval (TouchAccess)
access_countINTNOT NULL, default 0Incremented on retrieval, drives decay reset
superseded_byTEXTNULLPoints to newer contradicting drawer
cluster_idTEXTNULLCanonical drawer ID for merged clusters
retry_countINTNOT NULL, default 0Cold worker failure counter (max 3)
pipeline_tierTEXTNOT NULL, default 'llm'Which arm of the cold pipeline labelled this drawer: heuristic, centroid, or llm. Added by migration 000010.
entity_countINTNOT NULL, default 0Number of KG entities the enrichment worker wired up. Added by migration 000010.
triple_countINTNOT NULL, default 0Number of KG triples the enrichment worker wired up. Added by migration 000010.
filed_atTIMESTAMPTZNOT NULLWhen the memory was filed
created_atTIMESTAMPTZNOT NULLRow creation timestamp

Indexes:

  • idx_drawers_workspace on (workspace_id)
  • idx_drawers_workspace_wing on (workspace_id, wing)
  • idx_drawers_workspace_room on (workspace_id, wing, room)
  • idx_drawers_state on (state) WHERE state = 'raw' (cold worker polling)
  • idx_drawers_superseded on (superseded_by) WHERE superseded_by IS NOT NULL
  • idx_drawers_enrich on (workspace_id, created_at) WHERE state = 'processed' AND pipeline_tier <> 'llm' AND entity_count = 0 AND importance >= 3.0 — drives the memory_enrich River sweep. Predicate must match DrawerRepo.ListEnrichCandidates exactly.
примечание

No vector index exists on memory_drawers.embedding today. Migration 000008 is an intentional no-op: both HNSW and IVFFlat were tried first and both caused SIGILL crashes on Digital Ocean CPUs without AVX2. Sequential scan is the current backend, which is acceptable at the 10K-drawer-per-workspace ceiling enforced at write time by DrawerRepo.Add. See the commentary in migrations/orchestrator/000008_ivfflat_index.up.sql for the three workarounds to try once we move to AVX2-capable nodes.


memory_entities

Knowledge graph entity nodes. Each entity is a named thing (person, service, concept) scoped to a workspace.

ColumnTypeConstraintsDescription
idTEXTPK (composite)SHA256-based stable entity ID from normalized name
workspace_idUUIDPK (composite)Workspace scope
nameTEXTNOT NULLDisplay name
typeTEXTNOT NULL, default 'unknown'Entity classification (person, tool, concept, project, organization)
propertiesJSONBNOT NULL, default empty objectAdditional metadata
embeddingvector(1536)NULLEmbedding for semantic KG lookup fallback
created_atTIMESTAMPTZNOT NULLRow creation timestamp

Primary key: (workspace_id, id)


memory_triples

Knowledge graph temporal relationship edges. Each triple links two entities with a time-bounded predicate.

ColumnTypeConstraintsDescription
idTEXTPK (composite)Triple identifier
workspace_idUUIDPK (composite)Workspace scope
subjectTEXTNOT NULLSubject entity ID
predicateTEXTNOT NULLRelationship type
objectTEXTNOT NULLObject entity ID
valid_fromTEXTNULLWhen fact became true (YYYY-MM-DD)
valid_toTEXTNULLWhen fact ended (NULL = current)
confidenceREALNOT NULL, default 1.0Confidence score
source_closetTEXTNOT NULL, default ''Source drawer ID
source_fileTEXTNOT NULL, default ''Origin file
extracted_atTIMESTAMPTZNOT NULLExtraction timestamp

Primary key: (workspace_id, id)

Indexes:

  • idx_triples_subject on (workspace_id, subject)
  • idx_triples_object on (workspace_id, object)
  • idx_triples_predicate on (workspace_id, predicate)
  • idx_triples_validity on (workspace_id, valid_from, valid_to)

memory_identities

Per-workspace L0 identity text. One row per workspace, used to inject workspace context at the start of every conversation.

ColumnTypeConstraintsDescription
workspace_idUUIDPKWorkspace scope
contentTEXTNOT NULL, default ''L0 identity text (max 2,000 chars)
updated_atTIMESTAMPTZNOT NULLLast update timestamp

memory_type_centroids

Seven prototype vectors (one per memory type) used by the Phase 2 nearest-centroid classifier in the autoingest worker. A chunk in the [HeuristicConfidenceLow, HeuristicConfidenceHigh) confidence band is classified by picking the closest centroid; if cosine similarity exceeds MemoryCentroidThreshold (0.85) and the centroid has at least MemoryCentroidMinSamples (50) training samples, the drawer is persisted with pipeline_tier = 'centroid' and state = 'processed', bypassing the LLM cold path entirely. Added by migration 000011.

Centroids are rebuilt by the weekly memory_centroid_recompute River worker (Sunday 03:00 UTC) from the last 90 days of pipeline_tier = 'llm' drawers — training never pulls its own predictions, which prevents a feedback loop. See the MemPalace Memory Pipeline for the full rationale.

ColumnTypeConstraintsDescription
memory_typeTEXTPKOne of the seven memory types: decision, preference, milestone, problem, emotional, fact, task
centroidvector(1536)NOT NULLElement-wise average of the training-sample embeddings
sample_countINTNOT NULLSize of the training cohort. Rows with sample_count < 50 are ignored by NearestType lookups
computed_atTIMESTAMPTZNOT NULL, default NOW()When this centroid was last recomputed
source_hashTEXTNOT NULLMD5 over the sorted training sample IDs. The upsert is a no-op when this hash has not changed since the previous run, so unchanged centroids do not churn dead tuples
примечание

The table is empty on first deploy. Phase 2 is dormant until at least one memory type has accumulated 50 LLM-labelled samples — roughly the first week of real traffic on a new workspace. A best-effort 30-second startup seed (centroidSeedTimeout in cmd/crawbl/platform/orchestrator/orchestrator.go) warms the table once after riverClient.Start so operators do not have to wait until Sunday 03:00 UTC for the first recompute.


integration_connections

OAuth connections between users and external providers.

ColumnTypeConstraintsDescription
idUUIDPKConnection identifier
user_idUUIDNOT NULL, FK -> users(id) CASCADEUser reference
workspace_idUUIDNOT NULL, FK -> workspaces(id) CASCADEWorkspace scope
providerTEXTNOT NULLProvider name (e.g., gmail, slack)
statusTEXTNOT NULL, default 'active'Connection status
access_token_encryptedTEXTNULLEncrypted OAuth access token
refresh_token_encryptedTEXTNULLEncrypted OAuth refresh token
token_expires_atTIMESTAMPTZNULLToken expiry
scopesTEXT[]NOT NULLGranted OAuth scopes
provider_user_idTEXTNULLUser ID at provider
provider_user_emailTEXTNULLEmail at provider
metadataJSONBNOT NULLAdditional provider metadata
created_atTIMESTAMPTZNOT NULLCreation timestamp
updated_atTIMESTAMPTZNOT NULLLast update timestamp

Indexes: idx_integration_connections_unique UNIQUE on (user_id, workspace_id, provider)


model_pricing

Per-token costs for LLM models. Append-only — new rows inserted on price changes, old rows preserved for historical cost computation.

ColumnTypeConstraintsDescription
idUUIDPKRow identifier
providerTEXTNOT NULLLLM provider (e.g., openai)
modelTEXTNOT NULLModel identifier (e.g., gpt-4o)
regionTEXTNOT NULL, default 'global'Pricing region
input_cost_per_tokenNUMERIC(18,12)NOT NULLCost per input token (USD)
output_cost_per_tokenNUMERIC(18,12)NOT NULLCost per output token (USD)
cached_cost_per_tokenNUMERIC(18,12)NOT NULLCost per cached token (USD)
sourceTEXTNOT NULL, default 'manual'Price source
effective_atTIMESTAMPTZNOT NULLWhen this price takes effect
created_atTIMESTAMPTZNOT NULLRow creation timestamp

Indexes: idx_model_pricing_lookup on (provider, model, region, effective_at DESC)


usage_plans

Plan definitions. Seeded from migrations/orchestrator/seed/usage_plans.json.

ColumnTypeConstraintsDescription
plan_idTEXTPKPlan identifier (free, pro)
nameTEXTNOT NULLDisplay name
monthly_token_limitBIGINTNOT NULL, default 500000Tokens per month
daily_request_limitINTNULLDaily request cap (unused)
max_tokens_per_requestINTNULLPer-request cap (unused)
created_atTIMESTAMPTZNOT NULLCreation timestamp
updated_atTIMESTAMPTZNOT NULLLast update timestamp

usage_quotas

Per-user plan assignment. Active quota has expires_at IS NULL.

ColumnTypeConstraintsDescription
idUUIDPKRow identifier
user_idUUIDNOT NULL, FK -> users(id) CASCADEUser reference
plan_idTEXTNOT NULL, FK -> usage_plans DEFAULT 'free'Plan reference
effective_atTIMESTAMPTZNOT NULLWhen assignment started
expires_atTIMESTAMPTZNULLNULL = active
created_atTIMESTAMPTZNOT NULLCreation timestamp
updated_atTIMESTAMPTZNOT NULLLast update timestamp

Indexes: idx_usage_quotas_user_active UNIQUE on (user_id, plan_id) WHERE expires_at IS NULL


usage_counters

Monthly running totals per user. One row per (user_id, period).

ColumnTypeConstraintsDescription
user_idUUIDPK (composite), FK -> users(id) CASCADEUser reference
periodTEXTPK (composite)Billing period (YYYY-MM)
tokens_usedBIGINTNOT NULL, default 0Total tokens this month
prompt_tokens_usedBIGINTNOT NULL, default 0Input tokens
completion_tokens_usedBIGINTNOT NULL, default 0Output tokens
cost_usdNUMERIC(12,6)NOT NULL, default 0Accumulated cost (internal only)
request_countINTNOT NULL, default 0Number of LLM calls
last_updated_atTIMESTAMPTZNOT NULLLast increment timestamp

agent_usage_counters

Lifetime usage totals per agent.

ColumnTypeConstraintsDescription
agent_idUUIDPK, FK -> agents(id) CASCADEAgent reference
workspace_idUUIDNOT NULL, FK -> workspaces(id) CASCADEWorkspace reference
tokens_usedBIGINTNOT NULL, default 0Total tokens ever
prompt_tokens_usedBIGINTNOT NULL, default 0Lifetime input tokens
completion_tokens_usedBIGINTNOT NULL, default 0Lifetime output tokens
cost_usdNUMERIC(12,6)NOT NULL, default 0Accumulated cost (internal only)
request_countINTNOT NULL, default 0Number of LLM calls
last_updated_atTIMESTAMPTZNOT NULLLast increment timestamp

Indexes: idx_agent_usage_counters_workspace on workspace_id