Data model
Holotable uses two logical databases. In the default single-instance setup they are the same TimescaleDB instance.
Config store (PostgreSQL)
Section titled “Config store (PostgreSQL)”Metrics data never lives here — only configuration and validated specs.
sources
Section titled “sources”The registry: kind, safe config (jsonb), secret_ref, workspace_id,
catalog_refreshed_at, catalog_missing_tables, catalog_facts,
tombstoned_at. Credentials are never stored; secret_ref names an environment
variable family from which they are resolved at execution time.
kind says which shape config holds and which language the source’s queries
are written in, and a row whose config.kind disagrees with it is refused
when it is read:
kind |
config |
Queries |
|---|---|---|
timescaledb |
host, port, database, schema, ssl, tables (each with its columns and timeField), optional rowFilter { column, claim } |
SQL |
prometheus |
url, auth (none, bearer or basic), metrics (each with its type, help and labels), optional rowFilter { label, claim } |
PromQL |
loki |
url, auth (none, bearer or basic), labels (each stream label with the values discovery found), optional rowFilter { label, claim } |
LogQL |
duckdb |
path (relative to DUCKDB_SOURCES_DIR: a directory, or a file ending .duckdb), tables as for timescaledb, optional rowFilter { column, claim } |
SQL |
Source kinds
Section titled “Source kinds”A kind is a registered module, not a switch on the column (#382).
src/lib/sources/registry.ts lists the kinds; each declares its stored kind (never renamed), its strict
config schema, the connection, catalog and listing projections of a
source, and the language a panel against it carries. Its server half, under
src/lib/sources/server/, holds what the browser never reaches — discovery,
refresh, the connection test, validation, planning and execution — and a kind
without one is a compile error. Registering a kind is an import, never a lookup
by a string a request supplied, and test/source-kinds.test.ts fails on a kind
comparison or a src/lib/timescaledb/ or src/lib/duckdb/ import outside
src/lib/sources/.
The discriminator was defaulted rather than migrated: the TimescaleDB branch
reads a missing config.kind as timescaledb, so every config stored before
the union parses unchanged, and the next save writes kind into both the
column and the JSONB from the one value. No other kind may default its
discriminator. The language belongs to the kind, not the panel: a line chart
can be drawn from SQL or from PromQL, and what decides is what its source can
answer. A source’s kind cannot change on edit.
A Loki source (#562) is the third kind, and the Prometheus kind’s twin: the
same url and auth (one schema, src/lib/sources/http-config.ts), reached
through the same guarded exchange (src/lib/sources/server/endpoint.ts) under
SOURCE_URL_ALLOWLIST. Its allowlist is stream labels, at most 200, each
with up to 100 discovered values that are hints for the author and the model,
never compared by the guard. Every LogQL stream selector must carry an =
matcher on one of them. Its listing carries labelCount, never the URL or the
auth mode, and its rowFilter label is the tenant matcher spliced into every
selector. A log query’s answer becomes one row per line (time, message,
then a column per stream or parsed label); a metric query’s becomes the rows a
Prometheus answer does. See Loki sources for the
source and its panels, and Loki endpoints for what an operator
sets up.
secret_ref is nullable (migration 018) for a Prometheus or Loki source with
auth: none, which needs no credential, and for a DuckDB source, which never
names one; a TimescaleDB source and an authenticated HTTP source always name
one.
DuckDB
Section titled “DuckDB”A duckdb source (#572) is the second SQL kind: its panels carry the same
query.sql, checked by the same guard, planned by the same
buildExecutablePlan with the kind’s dialect (the window bound as UTC
TIMESTAMPs). What differs is where the rows come from. path names a
directory of Parquet, CSV and JSON files (one view per file directly under
it, named by its stem, not recursive; Parquet, then CSV, then JSON when two
share a stem) or a .duckdb file, opened READ_ONLY. It
is resolved by the path guard (src/lib/duckdb/path.ts) against
DUCKDB_SOURCES_DIR, both through realpath, and refused unless it lands
inside the root; unset, the variable refuses every DuckDB config, so the kind
is closed until an operator chooses what it may read. A path under uploads/
(CSV and JSON files a source admin uploaded from the browser, and the CSVs
an Excel workbook’s sheets were converted to, #595, #596, #597, and files
added to an upload source later, #604, src/lib/duckdb/uploads.ts) must be
one of the source’s own workspace’s,
uploads/<workspaceId>/<id>, as typed and as resolved. The guard runs when a
source is saved and again on every open. Each source gets one in-process
engine that is locked before anything a panel wrote can run: external access
off except for the source’s own files (allowed_paths, file by file, rather
than allowed_directories, because DuckDB lets a statement write wherever it
may read, and a directory prefix would let a statement the SQL guard missed
create files beside the source’s own), no extension installed or autoloaded,
memory_limit and threads from DUCKDB_MEMORY_LIMIT and DUCKDB_THREADS,
the engine’s TimeZone set to UTC, and lock_configuration, after which no
statement can change any of it. A query is interrupted at
QUERY_TIMEOUT_SECONDS, and rows stream through the same row and byte caps,
every cut reported as truncated. An engine’s error messages name files, so
each is scrubbed of paths before it reaches a panel, a Test report or the log;
a listing shows the table count and whether the source is a directory or a
database, never its path. A source’s own files stay writable by the engine
(DuckDB allows a write wherever it allows a read): the SQL guard, which
refuses everything but one SELECT, is what stops that, and mounting
DUCKDB_SOURCES_DIR read-only is the belt behind it.
The binding and the image. @duckdb/node-api is a native module with a
prebuilt binding per platform. It is loaded lazily, the first time a DuckDB
source needs it (src/lib/duckdb/binding.ts), never at import, so a server
whose platform has no binding boots and serves every other kind; there the
kind’s save check, Test and every execution say “DuckDB is not available on
this server”. The quick-start image stays on Alpine: the pinned binding ships
musl builds for linux-x64 and linux-arm64 beside the glibc ones, and the
binding was checked loading and answering on the image’s base
(timescale/timescaledb:2.30.2-pg16 with Alpine’s Node 24) on both. The
production image (node:24-bookworm-slim) is glibc.
Both images are targets of the one repository Dockerfile and share one
build of the app (#612): next build runs once, in its build stage on
glibc, and its output is JavaScript and static assets, the same on either
libc. What differs is node_modules, so each image takes its own for its
own base. The production image runs the standalone server with the
dependencies next build traced, on glibc like the build. The tracer copies
the binding’s duckdb.node but cannot see the libduckdb.so it loads with
the dynamic linker at run time, so outputFileTracingIncludes in
next.config.ts adds that library for the glibc bindings only (#615): npm
installs the musl packages on glibc too, and their library would add about
66 MB the runtime image never loads. The Build job checks the library is in
the standalone output, and the Compose smoke test runs a DuckDB panel
through the production image’s POST /api/query. The quick-start image
installs its production dependencies on Alpine, where npm and the binding’s
loader pick the musl builds, and copies the standalone server without the
traced node_modules, which carries the glibc library and lacks packages
the quick-start’s scripts need. CI builds the runtime image
first, and the quick-start build reports the build stage cached; a release
builds every target through the same stages. The quick-start image
ships no sample files (#574); the Compose stack has a
files demo. What a DuckDB source is
to a source admin is in DuckDB sources, and what
an operator sets up in DuckDB files.
Referenced sources are tombstoned rather than deleted, so dashboards referencing them keep resolving to a tombstone marker instead of breaking silently.
catalog_refreshed_at and catalog_missing_tables sit beside config rather
than inside it: config is the allowlist its author owns and the browser is
shown, while these two are what the last introspection found. They are what
catalog health is computed from, and only
the apply step of POST /api/sources/[id]/refresh writes them. A refresh is
previewed as a diff first, and applied only if a second introspection still
matches the digest the preview handed out.
catalog_facts (migration 026, #557) sits there for the same reason: it is
what the server is, not what the author allowed. Its shape is the kind’s;
for timescaledb it is { "timescaledb": "2.17.2" }, or
{ "timescaledb": null } for plain PostgreSQL; for duckdb it is the
engine’s version, { "duckdb": "1.5.6" }. Test
(POST /api/sources/[id]/test) and an applied refresh write it from what the
server answered; no request body sets it, it is not part of config, and a
value that no longer parses reads as null, never recorded, which keeps the
behavior from before the column. See
PostgreSQL without TimescaleDB.
dashboards
Section titled “dashboards”Identity: workspace_id, title, created_by, current_version_id,
deleted_at. Deletion is a soft delete.
Plus workspace metadata: description and tags text[]. These are about
the dashboard rather than part of it — nothing executes them, they are not in
the spec IR, and they do not travel in an export — which is why editing them
writes the row in place instead of appending a version, and why they cost no
specVersion bump.
dashboard_favorites
Section titled “dashboard_favorites”user_sub, dashboard_id, created_at. Favoriting is per person, so it
keys on the identity’s subject and sits outside the dashboard row everyone
shares; the API takes the subject from the validated session and never from a
request field. ON DELETE CASCADE, because a favorite of a deleted dashboard
is a bookmark to nothing rather than a dangling reference.
dashboard_versions
Section titled “dashboard_versions”Append-only: dashboard_id, version, the entire validated spec as
jsonb, and an optional note — the author’s own one line about what changed,
written in the editor and displayed as-is. A new row is written on every save;
existing rows are never mutated.
This is the property that makes viewing and polling pure replays of a fixed
spec, and it means a saved dashboard is a stable, auditable artifact. The
history is readable at /dashboards/[id]/versions, and restore follows the
same rule: it appends a new row copying the old spec (noted restored from vN)
rather than moving current_version_id back.
A dashboard keeps its newest DASHBOARD_VERSIONS_KEEP versions (default 100,
0 keeps every one, #494). A save past the cap deletes the oldest in the same
transaction. The version just written is current and the newest, so it is
never among them. Share links show the current version, so none is pinned to
an old one. The history page says when older versions are gone.
templates
Section titled “templates”A reusable spec: workspace_id, kind (panel or dashboard), name,
description, and body as jsonb. The body is the IR — a Panel or a
Dashboard tagged with which one — so it is validated against the same schema
on write and on read, and it carries no connection detail or credential for the
same reason a dashboard version does not. A stored body is upgraded the same
way a version row is. A dashboard records its own specVersion, and a panel
body records it beside the panel.
Two constraints hold the row together: kind = body->>'kind', so the column
can be filtered on without becoming a second opinion about the contents, and
UNIQUE (workspace_id, kind, name), because two rows that read identically in
a picker are a bug rather than a feature (the API answers that clash with a
409).
Deleting a template is a hard delete. Instantiating one copies its spec into an ordinary dashboard, so unlike a source there is never a reference left pointing back at the row.
chat_messages (dropped)
Section titled “chat_messages (dropped)”The dashboard chat’s history before #416. Migration 020 copied every row into
conversations and conversation_messages; migration 021 dropped the table.
Its rollback recreates it from the conversations that continue a dashboard’s
chat.
conversations
Section titled “conversations”One person’s Explore conversation (#416, the Chat engine): id, user_sub, workspace_id,
source_ids, dashboard_id (set when it continues a dashboard’s chat; ON DELETE SET NULL), title, time_range (an IR TimeRange), variables,
model_id (the catalog model its turns use, #442: a model’s uuid or
env:<name>, NULL for the default, checked on every turn and never a foreign
key, so a deleted model falls back to the default) and the two timestamps. Personal like user_preferences: every statement filters
on user_sub from the session, and no route reads another person’s.
A conversation with a dashboard_id continues that dashboard’s chat: at most one per person per dashboard (a partial unique index), with no source_ids of its own; its sources are the dashboard’s, re-resolved from the current spec on every turn.
Nothing in a row is authorization. source_ids are re-resolved and
re-authorized on every turn and every panel run; workspace_id is derived from
the source records when the conversation is made, never from a request.
Bounded per person by CHAT_CONVERSATIONS_MAX (the least recently used go
first) and by CHAT_HISTORY_RETENTION_DAYS (one with nothing newer is gone),
swept when a conversation is created and applied on read.
conversation_messages
Section titled “conversation_messages”One message of a conversation, as chat_messages holds one: the SDK’s own
id, role and the whole message in content, keyed on (conversation_id, id) and cascading with the conversation. A drawn panel’s result rows are
never stored: persistableMessage reduces each showPanel output to the
panel id, columns, row count and five sample rows, and the page runs the panel
again from its stored spec. Read back as untrusted; a panel whose spec no
longer parses comes back as an error part. Bounded per conversation by
CHAT_HISTORY_MAX_MESSAGES and CHAT_HISTORY_RETENTION_DAYS, swept with each
write.
generation_log
Section titled “generation_log”One row per model generation, or per panel an Explore turn draws (mode = 'chat'): mode, source_id, prompt_redacted,
catalog_hash, spec, model, attempts, input_tokens, output_tokens,
error. It answers the question a wrong dashboard raises — what was asked, and
what came back — and it is the corpus the eval harness
(#24) will read.
Three things keep it safe to hold. The prompt is stored redacted
(redactPrompt in src/lib/ai/log.ts), because people paste connection
strings into free text. The catalog is stored as a hash, not as text: “was
this the same catalog?” is the question the column answers, and the schema
itself is not needed to answer it. spec is a validated IR spec, which by
construction carries opaque source ids and no connection detail.
Written on the stream’s finish callback and never on a read path; a write that
fails is logged and dropped rather than failing the generation. Read only by a
workspace source-admin (or a platform admin) through GET /api/generation-log
— never on a dashboard, source or spec payload. Swept on write by
GENERATION_LOG_RETENTION_DAYS, and the same window is applied on read, so
shortening it takes effect at once.
The retention sweep (#494, src/lib/retention.ts) deletes the same rows
on a timer. That covers the generation log, conversations and conversation
messages past their retention, so a workspace nobody writes to is swept too.
It runs every RETENTION_SWEEP_INTERVAL_MS (default 1 hour, jittered by up to
a tenth, 0 turns it off). It deletes in batches of 1,000 and logs a
retention.swept line per run. It also counts holotable_retention_deleted_total{table}.
It never touches audit_log, which is append-only. Pruning that table is the
operator’s step in the audit log.
There is deliberately no foreign key to sources: a log entry outliving the
source it names is the normal case, and a cascade would erase exactly the
history someone came looking for.
audit_log
Section titled “audit_log”One row per event (#30):
at, workspace_id, actor_sub, actor_kind, action, resource_type,
resource_id, outcome, request_id, detail. Who signed in and out, what
was created, changed, deleted or run, and every refusal; the list is
AUDIT_ACTIONS in src/lib/audit.ts and the
audit log page.
It is append-only: triggers refuse UPDATE, DELETE and TRUNCATE for
every role, the owner included, because the app and the migrations share one
role and a grant cannot bind a table’s owner. detail goes through the log’s
redaction pass on the way in, with SQL and prompts reduced to a digest and
any result-shaped key dropped. Written fire-and-forget by audit(), so a failed
write is logged and counted rather than failing the request. Read only through
GET /api/audit. Nothing removes rows; pruning is a documented maintenance
step. Like generation_log, it has no foreign keys: a row outliving the
dashboard or source it names is the point.
llm_usage
Section titled “llm_usage”Token counters per (workspace_id, day, route, model): input_tokens,
output_tokens, requests. Each finished model call adds to its row. Never
prompts, specs, or output. Read before every model request to enforce the
daily budget; see LLM rate limits and budgets.
llm_models
Section titled “llm_models”The model catalog (#439): one row per workspace or personal model. id
(uuid), scope (workspace or personal), workspace_id (for a workspace
model) or user_sub (for a personal one), name (unique per owner, ignoring
case), provider (a provider kind, no CHECK, as kinds are code),
settings (the kind’s browser-safe settings, validated on read),
credentials (sealed: AES-256-GCM under a key derived from SESSION_SECRET
with its own label; a bare API key, or a JSON object of the kind’s fields;
NULL for none), created_by, updated_by and the two timestamps. Every
statement filters on the owner from the path or the session, so an id alone
reaches nothing. No route returns credentials. Server models are never
stored: they come from the environment. See Models and providers.
workspace_llm_config
Section titled “workspace_llm_config”One row per workspace that has chosen something about models: default_model
(a workspace model’s id or env:<name>, NULL for the server’s default;
checked in code, cleared when that model is deleted), allow_personal_keys,
updated_by, updated_at. Migration 017 also gave it a single model slot
(provider, settings, api_key) and a per-person user_llm_config table;
022 copied them into llm_models and 024 dropped them.
workspace_limits
Section titled “workspace_limits”Optional per-workspace overrides of LLM_RATE_PER_MINUTE and
LLM_DAILY_TOKEN_BUDGET: rate_per_minute, daily_token_budget. A NULL
column inherits the environment; 0 disables that limit. Platform admins edit
it from Settings → Workspaces through PATCH /api/workspaces/[id]/limits.
workspace_prompts
Section titled “workspace_prompts”One row per workspace that has a prompt customization (#66): glossary
(text), metric_definitions and examples (JSONB arrays), updated_by,
updated_at. Each example is { prompt, specVersion, panel }, a lone panel
recording its IR version as a panel template does, so it is upgraded on read.
A row is read through the WorkspacePrompt schema; one that no longer parses
is logged and treated as no customization. Written only by
PUT /api/workspaces/[id]/prompt. See
Workspace context.
user_preferences
Section titled “user_preferences”One row per subject: sub (primary key), prefs (JSONB), updated_at. It
holds the choices that follow a person between devices: time zone, clock,
start page and dashboard list defaults, chart patterns, whether dashboards draw
the chat button, which recents and conversations are kept, Explore’s defaults,
and the model last picked in each workspace (modelByWorkspace, #442, written by the server when a request
names a model). Keyed by sub alone, because a
preference is personal and not workspace-scoped. Read through
parsePreferences in src/lib/preferences.ts, which validates field by field
and drops or defaults anything stale, so an old row never breaks a page. Only
GET and PATCH /api/me/preferences touch it, and only for the caller’s own
sub. Theme and motion are deliberately not here; see
Settings and your account.
sessions
Section titled “sessions”One row per renewable session (#27): id_hash (SHA-256 of the opaque id in
the /api/auth cookie, never the id itself), sub, oidc_sid (the realm’s
session id, which back-channel logout deletes by, #28), refresh_token (AES-256-GCM
ciphertext under a key derived from SESSION_SECRET), created_at,
refreshed_at and expires_at. Written at sign-in, rewritten at each renewal
under a row lock (so concurrent renewals take turns with a rotating refresh
token), and deleted at sign-out, on a refused renewal, or once expired.
Nothing on the request path reads it. Rotating SESSION_SECRET makes every
stored token unreadable, which ends every session.
annotations
Section titled “annotations”One workspace event drawn on time-series panels (#68): workspace_id, at,
an optional ended_at (a range, such as an incident), kind (deploy,
incident or note), title, description, tags, created_by,
created_at, and source (manual, or the name of the pipeline that posted
it). Every statement filters on workspace_id: a read takes it from the
dashboard record, a write from the path. See
Annotations.
dashboard_shares
Section titled “dashboard_shares”One read-only share link (#65): dashboard_id, workspace_id, token_hash
(SHA-256 of the hts_ token, never the token), label, allowed_origins,
an optional pinned time_range, created_by, created_at, expires_at,
revoked_at and last_used_at. Checked on every use of the token, so
revoking takes effect on the next request. See
Share links and embedding.
api_tokens
Section titled “api_tokens”One service-account API token (#288): workspace_id, name, token_hash
(SHA-256 of the ht_ token), role (viewer or editor only, by a CHECK),
created_by, created_at, expires_at, revoked_at and last_used_at. See
Service-account API tokens.
Metrics store (TimescaleDB)
Section titled “Metrics store (TimescaleDB)”timescaledb/init/001_schema.sql creates the demo schema:
metrics.http_requestsis a hypertable of raw request events. A continuous aggregate,metrics.http_requests_1m, pre-aggregates per-minute request, error, duration and byte statistics; a seven-day retention policy removes old raw chunks.metrics.system_metricsholds per-host infrastructure samples, andmetrics.holotable_selfthe app’s own Prometheus instruments, scraped byscripts/self-metrics.ts. See Demo data.- A read-only role is created by
timescaledb/init/002_readonly_user.sh. The app only ever connects as this user, via the source’ssecret_ref.
Migrations
Section titled “Migrations”scripts/migrate.ts applies migrations/*.sql in filename order inside a
transaction, recording each in schema_migrations so it runs once. Every
migration declares a rollback or an explicit reason it has none, concurrent
runs serialize on an advisory lock, and --check is the pipeline gate against
deploying code ahead of its schema. See
Database migrations.
Last verified against the code at commit 00ea858 (2026-10-05).