// PART 05
Models and database
All structured state lives in PostgreSQL behind Diesel, with one rule that
shapes everything: every table! macro lives in the botschema crate and
nowhere else.
The rule
table! / joinable! / allow_tables_to_appear_in_same_query! are declared
only in botschema (#1497). Feature crates consume them via
botschema = { workspace = true, features = ["people", "billing"] } and
re-export what they use (pub use botschema::<table>;). Copying a table
declaration into a feature crate is the exact drift this rule closes — the
same table was once declared 16× with incompatible Rust types.
Domains
Tables are grouped by domain and compiled behind Cargo features. The counts
below are generated from botschema/src/**:
| Domain | Tables | Domain | Tables |
|---|---|---|---|
agents |
9 | mail |
15 |
analytics |
1 | marketplace |
3 |
attendant |
11 | meet |
9 |
autotask |
6 | memory |
1 |
billing |
25 | people |
44 |
browse |
3 | project |
5 |
calendar |
5 | research |
9 |
canvas |
5 | runs |
1 |
channels |
2 | security |
6 |
cloud |
8 | social |
13 |
compliance |
18 | tickets |
6 |
consent |
2 | video |
8 |
core |
34 | weba |
4 |
dashboards |
5 | workspaces |
14 |
database_manager |
2 | desktop |
2 |
drive |
4 | email_integration |
6 |
goals |
7 | integrations |
7 |
learn |
7 | — | — |
Totals: 307 tables · 3592 columns · 35 domains · 189 join
edges · 19 allow_tables_to_appear_in_same_query! groups. 48 tables are
always available; the rest sit behind their feature gate.
Core tables a developer meets first
| Table | Holds |
|---|---|
bots |
registered bots discovered by the drive monitors |
users, user_sessions |
identities and sessions |
message_history |
chat transcript per session |
basic_tools |
compiled tool definitions from .bas headers |
agent_runs, agent_spans, run_events |
turn/run observability |
consent_* |
consent grants, pending prompts, audit |
workflow_executions |
WORKFLOW-mode step state (planned feature) |
The full column-level reference (primary keys, nullability, defaults, indexes, foreign keys) is generated — see the schema reference page.
Adding a table
The walk-through is in Adding a new app or API; the schema part is:
cd botserver
diesel migration run # applies migrations/{version}-{name}/up.sql
diesel print-schema # see what the database now looks like
# update the matching botschema module, then commit migration + botschema together
Conventions: id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(). A #[derive(Queryable)]
struct must never disagree with its table! on a column type.
Where the database does not apply
- Bot packages, KB documents and user files live in Drive (object storage), not in tables.
- Suggestions, pub/sub and short-lived counters live in Valkey.
- Credentials live in Vault.
- App data created by generated apps uses the
user_datavirtual-table system (/api/db/*), which namespaces per app instead of running migrations per app.