New Phase 1 Platform database — PostgreSQL, separate from the Lab image's own SQLite (which keeps its current students/progress data untouched, decision #2 / correction C in docs/LAB_ARCHITECTURE.md). Schema (platform/provisioner/migrations/): - lab_hosts: the abstraction that keeps Docker connectivity out of code — endpoint (unix:// or tcp://+TLS), enabled flag. Phase 1 ships one row. - environments: environment_id (UUID), student_id (opaque external identifier, no FK — students table isn't in this database yet), lab_host_id (real FK), status, routing_token (CSPRNG via crypto.randomBytes, opaque), container/ network identity, resource limits, lifecycle timestamps. - environment_events: append-only audit trail, one row per lifecycle transition, never logs the routing token in plaintext (see lifecycle.js's redact()). File-based migration runner (db.js) matching the check-before-alter idempotency pattern already used in the Lab image's backend/server.js, applied on every Provisioner boot. Resource limits and the lab_hosts seed are config files (config/resource-policy.yaml, config/lab-hosts.seed.yaml), not database tables — there's no admin UI to manage them via a database yet, so a DB-backed policy table would just be a write path nothing uses. Co-Authored-By: Claude Sonnet 5 <[email protected]>
18 lines
1.0 KiB
SQL
18 lines
1.0 KiB
SQL
-- environment_events — audit trail for every lifecycle transition.
|
|
-- See docs/LAB_ARCHITECTURE.md §3/§8 and docs/PHASE1_PLATFORM_FOUNDATION.md §2/§9.
|
|
-- Never log secrets or routing tokens in plaintext here (see lifecycle.js emitEvent()).
|
|
|
|
CREATE TABLE IF NOT EXISTS environment_events (
|
|
id BIGSERIAL PRIMARY KEY,
|
|
environment_id UUID NOT NULL REFERENCES environments(environment_id),
|
|
event_type TEXT NOT NULL, -- provision_requested | host_selected | network_created |
|
|
-- firewall_configured | container_created | ready |
|
|
-- reset | destroyed | error | reaped_idle | suspend | resume
|
|
actor TEXT NOT NULL, -- 'system' | 'instructor:<id>' | 'student:<id>' | 'reaper'
|
|
detail JSONB,
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_env_events_environment ON environment_events(environment_id);
|
|
CREATE INDEX IF NOT EXISTS idx_env_events_type ON environment_events(event_type);
|