Skip to content
Kaiov0.8.0

Database schema

Migrations live in backend/migrations/ and are embedded in the core crate with sqlx::migrate!. They run automatically on startup, and they are the single source of truth for the schema, including in tests.

Table Description Key columns
stacks Metadata and health status for Compose projects id, name, current_version, update_available, outdated_images, env_pending
stack_versions Historical snapshots of docker-compose.yml and their environment stack_id, version, content (YAML), env_snapshot (JSON)
stack_env Current environment variables of a stack, including changes not yet applied stack_id, key, value, secret
containers Real-time mirror of container state on the host id, name, stack, state, image, ports (8080:80, or 127.0.0.1:8080:80 for a port bound to one address)
container_metrics Time-series history for CPU, RAM and network I/O, kept when the container goes away container_id, stack, container_name, cpu_pct, memory_mb, network_rx_bps, timestamp
events Audit log of system, container and stack lifecycle events id, kind, entity_id, message, level, timestamp
cluster One row: this server’s own identity and signing key, and the cluster it has itself joined id (this server’s identity), signing_key (Ed25519 seed), control_plane_url, control_plane_key (the public key it trusts), node_name, joined_at
join_tokens The join tokens minted and not spent yet, by hash hash (SHA-256), created_at, expires_at
cluster_nonces The nonces of the signed cluster calls this server accepted, kept ten minutes so none is accepted twice nonce, seen_at
nodes The Kaio servers that have joined this one, with the result of each one’s last probe id (the joined server’s own identity), name, url, public_key (pinned on joining), status, version, last_seen, last_error
audit_log Who did each sensitive action, refusals included, kept KAIO_AUDIT_RETENTION_DAYS days. See Security at, actor, source, via, level, action, target, outcome, status, detail
image_scans Latest Trivy scan per image, with severity counts and the full CVE list id (image ID), image_name, status, critical_count…total_count, vulnerabilities (JSON)
Index Why
container_metrics(timestamp) Retention cleanup and time-window queries for the sparklines
stack_versions(stack_id) Version history lookups
image_scans(image_name) Backs the vulnerability join hit on every dashboard poll
nodes(name) Nodes are addressed by name on every route and command
audit_log(at) Retention cleanup and the newest-first listing
containers(image) The other side of that join (image_scans.image_name ⨝ containers.image), also used by the rescan cleanup delete

Events are deleted after KAIO_EVENTS_RETENTION_DAYS days (default 30), and audit entries after KAIO_AUDIT_RETENTION_DAYS (default 90). Metrics accumulate in container_metrics for KAIO_METRICS_RETENTION_HOURS hours (default 24). The dashboard reads a window of 1 hour up to that retention (12 by default), averaged per stack and container name into buckets of ten seconds per hour of window, so two minutes over 12 hours. A container recreated under the same name, as an update does, keeps its history.

Terminal window
# in backend/migrations/, create <timestamp>_<name>.sql
make verify # tests run the migrations from scratch

Never edit an applied migration; add a new one. The test suite builds its database from the same files, so a migration that breaks is caught before it reaches a deployment.

Kaio, built by Régis Gaidot