# Data model

> The tables of the Cases server.

Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service).  
Source: https://cases.docs.sypnia.com/architecture/data-model/

For agents: Schema cases on any Postgres 14+, owned by the server's role (no superuser), applied at start with cases.migrations. Tables: people(user_id, email, name), workspaces(id, slug, name, sypnia_org_id), members(workspace_id, user_id, role owner|editor|approver), reviewers(workspace_id, user_id), invitations(workspace_id, email, role, accepted_at), maps(id, workspace_id, slug, name, repository, data_project, telemetry_project, required_approvals jsonb {count}), versions(map_id, number unique per map, proposal_id, created_by, approved_by[], summary, map_file json, navigation json, map_text, navigation_text: the files as written), version_cases(version_id, case_id, area, body json, text: the case file as written, null when a proposal changed it), proposals(id, map_id, base_version, title, reason, status draft|open|merged|closed, source api|upload|mcp, author, map_file, navigation, findings jsonb, merged_version), proposal_changes(proposal_id, position, op add|change|retire, case_id, area, body json), proposal_reviewers(proposal_id, email, user_id, required), approvals(proposal_id, user_id, role), comments(map_id, proposal_id?, case_id?, field?, body, author), check_results(map_id, version, findings, summary, code), project_tokens(map_id, name, token_hash SHA-256, last4, scopes, expires_at, revoked_at), links(map_id, kind data|telemetry|repository, ref, api, secret encrypted, reverse), mail_outbox, audit(workspace_id, map_id, actor, action, target, detail). Case bodies, map.yaml and navigation.yaml stored as json (not jsonb) to keep the order people wrote. versions, version_cases and audit refuse UPDATE and DELETE by trigger. Access is checked by the API on every request (roles, scopes), and again inside an approval's transaction; no row-level security on these tables.

The server keeps everything in one Postgres schema, `cases`, on any Postgres 14+. It creates the schema on its first start and applies its migrations there (recorded in `cases.migrations`); its database role owns the tables and needs no superuser.

| Table                                                 | Holds                                                                                                                                                                                                                                                                                                                                 |
| ----------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `people`                                              | everyone who signed in: their id, e-mail and name                                                                                                                                                                                                                                                                                     |
| `workspaces`, `members`, `reviewers`, `invitations`   | who belongs where and their role (owner, editor, approver), the reviewers invited to a workspace, and invitations by e-mail not accepted; a workspace maps to a Sypnia organization in Sypnia Cloud                                                                                                                                   |
| `maps`                                                | a map, its connected repository, its linked Data and Telemetry projects, and how many approvals a proposal needs                                                                                                                                                                                                                      |
| `versions`                                            | every approved version: number (unique per map), the proposal it came from, who proposed and approved, when, summary, and that version's `map.yaml` and `navigation.yaml`, with the text of each file as it was written (`map_text`, `navigation_text`)                                                                               |
| `version_cases`                                       | the full body of every case in a version, with its area, so any version can be read without replaying history; and, for a version made from files, the file's text as written (`text`), so `cases pull` and the export give it back byte for byte. A case a proposal changed has no text and is written in the format's compact style |
| `proposals`, `proposal_changes`, `proposal_reviewers` | drafts, open and past proposals, the changes in each, in order, and the reviewers named on each                                                                                                                                                                                                                                       |
| `approvals`, `comments`                               | approvals per proposal (with the approver's role), and comments per proposal, case or field                                                                                                                                                                                                                                           |
| `check_results`                                       | the last check per map and version, with the code side it compared                                                                                                                                                                                                                                                                    |
| `project_tokens`                                      | the Cases project tokens: name, scopes, expiry, the SHA-256 of the token and its last 4 characters                                                                                                                                                                                                                                    |
| `links`                                               | each map's links to Data, Telemetry and its repository; a token of another product is kept encrypted                                                                                                                                                                                                                                  |
| `mail_outbox`                                         | review e-mails waiting to be sent, with their retries                                                                                                                                                                                                                                                                                 |
| `audit`                                               | every change: who, what, when                                                                                                                                                                                                                                                                                                         |

Case bodies, `map.yaml` and `navigation.yaml` are stored as `json`, not `jsonb`: `jsonb` reorders the keys of an object, and the order people wrote outcomes and fields in is part of the file. Findings, details and settings are `jsonb`.

The runtime's tables are not here: `subscriptions`, `outbox`, `deliveries` and `processed_events` live in the schema `sypnia_cases` of **your app's** database, next to the data they describe ([Delivery](https://cases.docs.sypnia.com/runtime/delivery#the-tables)).

Versions are immutable: a trigger refuses every `UPDATE` and `DELETE` on `versions`, `version_cases` and `audit`, so they only grow. The API checks the caller's role and the token's scopes on every request, and checks the role again inside an approval's transaction ([Security](https://cases.docs.sypnia.com/security)). The map's files in a repository are a projection of a version, never the other way round: a change in the files becomes a proposal first.
