chain-rdeveloper portal
build

Database Schema

Overview

The platform uses two PostgreSQL databases, one per service:

DatabaseServiceDocker service
postgres-aisvc-aipostgres-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

TableDescription
organisationsOrganisations (mapped to Auth0 organisations)
user_organisationsUser ↔ organisation membership with role
projectsUser/org-scoped projects
user_projectsUser ↔ project membership with role
rolesRole definitions
permissionsPermission codes attached to roles
audit_logsAction audit trail

AI Primitives

TableDescription
agent_toolsTool assignments to agents
agent_repositoriesKnowledge repository grants to agents (the only way an agent gets retrieval access — never an individual source)
agent_skillsSkill assignments to agents
agent_memoryAgent conversation memory entries
conversationsChat sessions (linked to agent or model)
chat_messagesIndividual 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_segmentsPer-worker output segments for multi-agent skills
uploaded_filesParsed 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

TableDescription
knowledge_documentsDocument metadata; actual content stored in MinIO
knowledge_repositoriesNamed collections grouping knowledge bases into one unit an agent can integrate
repository_knowledgeKnowledge base membership within a repository
knowledge_citationsWhich source (and document) each answer cited, stamped with its workspace — the record of use (migration 110)

Tools & Workers

TableDescription
custom_workersUser customisations of built-in worker agent definitions
worker_toolsTool assignments to custom workers
mcp_serversMCP server connection configurations

Execution

TableDescription

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

TableDescription
experiment_variantsNamed prompt/config variants within an experiment
experiment_runsSingle scored execution of one variant
test_suitesDataset of test cases
test_casesIndividual test case (input + expected output)
test_suite_runsFull suite execution
test_case_resultsPer-case result within a suite run

Simulation

TableDescription
simulation_scenariosNamed evaluation scenario within a world
simulationsExecution of agent clusters within a world/scenario

Reference Data

TableDescription
resource_rolesRole tags for resources
skillsSkill graph definitions

svc-ai Entity Groups

svc-ai owns postgres-ai. Its schema covers:

TableDescription
llm_modelsModel registry per provider
llm_invocationsTraced invocations (used for usage stats)
llm_invocation_callsEach 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/.