Database Schema
Overview
The platform uses two PostgreSQL databases, one per service:
| Database | Service | Docker service |
|---|
postgres-ai | svc-ai | postgres-ai (port 5433) |
Each service owns its schema exclusively — no cross-database foreign keys. svc-core and svc-ai communicate via internal API calls.
Canonical Reference
The authoritative, auto-generated model documentation is in spec/models/database.md. It is regenerated from SQLAlchemy source with make spec. Do not duplicate it here.
svc-core Entity Groups
Managed by Alembic migrations. Key entity groups:
Identity & Access
| Table | Description |
|---|
organisations | Organisations (mapped to Auth0 organisations) |
user_organisations | User ↔ organisation membership with role |
projects | User/org-scoped projects |
user_projects | User ↔ project membership with role |
roles | Role definitions |
permissions | Permission codes attached to roles |
audit_logs | Action audit trail |
AI Primitives
| Table | Description |
|---|
agent_tools | Tool assignments to agents |
agent_repositories | Knowledge repository grants to agents (the only way an agent gets retrieval access — never an individual source) |
agent_skills | Skill assignments to agents |
agent_memory | Agent conversation memory entries |
conversations | Chat sessions (linked to agent or model) |
chat_messages | Individual messages with role, content, token count, trace; a user message's meta holds the chat command it ran (command) and the documents it attached (attachments, by id) |
chat_message_segments | Per-worker output segments for multi-agent skills |
uploaded_files | Parsed files stored for reuse across sessions; status is reading until docling has read the text in the background, then ready or failed (with error). The original as uploaded is in MinIO at object_key (uploads/{id}/original, migration 109; null before), with size_bytes. A chat message names the files it attached in meta.attachments (Attachments) |
Knowledge
| Table | Description |
|---|
knowledge_documents | Document metadata; actual content stored in MinIO |
knowledge_repositories | Named collections grouping knowledge bases into one unit an agent can integrate |
repository_knowledge | Knowledge base membership within a repository |
knowledge_citations | Which source (and document) each answer cited, stamped with its workspace — the record of use (migration 110) |
| Table | Description |
|---|
custom_workers | User customisations of built-in worker agent definitions |
worker_tools | Tool assignments to custom workers |
mcp_servers | MCP server connection configurations |
Execution
The tasks, pipelines and their run tables are gone: tasks were dropped in migration 24 and pipelines, whose router was never mounted, in migration 92. A chat turn is recorded on its messages; svc-ai's model and tool calls are in its own llm_invocations and tool_invocations.
Evaluation
| Table | Description |
|---|
experiment_variants | Named prompt/config variants within an experiment |
experiment_runs | Single scored execution of one variant |
test_suites | Dataset of test cases |
test_cases | Individual test case (input + expected output) |
test_suite_runs | Full suite execution |
test_case_results | Per-case result within a suite run |
Simulation
| Table | Description |
|---|
simulation_scenarios | Named evaluation scenario within a world |
simulations | Execution of agent clusters within a world/scenario |
Reference Data
| Table | Description |
|---|
resource_roles | Role tags for resources |
skills | Skill graph definitions |
svc-ai Entity Groups
svc-ai owns postgres-ai. Its schema covers:
| Table | Description |
|---|
llm_models | Model registry per provider |
llm_invocations | Traced invocations (used for usage stats) |
llm_invocation_calls | Each model call within an invocation, with its model and node |
See spec/models/database-ai.md for the full auto-generated reference.
Migrations
Schema changes are managed with Alembic per service:
make db-migrate # Run Alembic upgrade head (svc-core)
make db-reset # Drop, recreate, and migrate (destroys data)
make db-shell # psql shell into postgres-core
Migration files live in modules/svc-core/alembic/ and modules/svc-ai/alembic/.