Data model
All persistent state is in PostgreSQL. The schema is managed with SQL migrations, applied by goose: the server's own in backend/migrations/, then each module's from backend/modules/<module>/migrations/ in module order, each recorded in a version table of its own.
| Table | Notes |
|---|---|
users | status = deleting marks a user whose personal team is still being torn down. |
roles, user_roles | The built-in roles are rows so that assignments are foreign keys; their permissions come from code. |
teams, team_members | One personal team per user (personal_user_id is unique). The team row is the lock for quota checks and metering. |
credit_ledger | Amounts in millicredits. key makes entries idempotent: one usage entry per day, one allowance per period. |
user_identities | Links a user to (provider, subject) pairs of identity providers. Removed with the user. |
templates, template_revisions | A revision's source is stored as written. At most one revision per template is a draft or pending (a partial unique index); a submitted revision never changes, so an approval covers what was read. |
workers | Where workspaces run; see Workers. The row named local is created by the first migration and gets its token from the deployment. A worker with workspaces or volumes cannot be deleted. |
variables | Environment variables of a user or a workspace, sealed with the secret key (AES-GCM). Triggers on variables, ssh_keys and team_members raise workspaces.config_revision from the sequence workspace_config_revisions for the workspaces whose sidecars serve what changed, as do changes of users.status; a contribution raises it for what it reads (Workspaces.Revise, Reconfigure). |
workspaces | Reconciled. The id is a random 10-character string of lower-case letters and digits, valid as a DNS label and as a Kubernetes name suffix. |
volumes, volume_mounts | Reconciled. Same id format. A volume is mounted by one workspace, or by any number when it is shared (a partial unique index); a mount may be read-only. A volume waits unbound, without a worker, until its first workspace places it, and is lost when its worker no longer has it. The volume's workspace_id and mount_path columns are no longer used. |
jobs, job_schedules | Background jobs and the state of their schedules. |
settings | One row per settings section, holding only the fields an operator has overridden. |
audit_logs | Append-only. actor_id is deliberately not a foreign key: a record must outlive the user. |
workspaces and volumes also carry the reconciliation columns worker_id, generation, observed_generation, reconcile_at, lease_until, claims, failures, deleted_at, phase, status_code and status_message, described under Reconciliation.
The diagram leaves out what hangs off these rows in other modules: the sign-in credentials of a user (api_tokens, ssh_keys, avatars, recovery_codes, webauthn_credentials), the agents of a worker and their logs (worker_agents, worker_agent_logs, worker_state with the epoch), the network between workspaces (network_rules, network_workers), notifications (notification_inbox, notification_preferences, notification_announcements), clusters (cluster_clusters, cluster_members, each node a workspace), the outbox of events (events), and the tables of plugins, named after them.
Not in PostgreSQL: refresh tokens, pending identity-provider sign-ins and buffered workspace activity live in Valkey under the idekube: key prefix and may be lost without affecting any resource.