Files
oikos/migrations/012_client_enrollment.up.sql
dtoro 5b22f2367b
Some checks failed
ci / build-test (push) Has been cancelled
ci / docker-build (push) Has been cancelled
test: e2e client lifecycle + ADRs with sequence diagrams
- client_lifecycle_test.go: full end-to-end integration test
  planned → provisioning (enroll) → active → migrating → active →
  deprecated → failed. Validates age keypair generation, attrs,
  context/secrets endpoints, invalid transition blocking, compute
  entity provisioning with relationship edges and status tracking.
  Also tests enrollment rejection for invalid states and duplicate
  slug rejection for provisioning.

- adr/0011-client-lifecycle-flows.md: workstation self-enrollment,
  compute entity provisioning, deprecation/destruction flows with
  Mermaid sequence diagrams. Full lifecycle state diagram. Transition
  check enforcement documentation.

- adr/0012-hermes-oikos-interactions.md: Hermes ↔ Oikos interaction
  flow through OODA loop phases. Thin client bootstrap. Internal
  component interactions (scheduler, actuator, notifier). Complete
  30-tool ownership matrix.

- Fix: migration 012 FK reference (executions.id → executions.entity_id)
- Fix: provision handler null attributes JSONB
- Fix: provisioning steps use entity_id for execution FK

All 3 integration tests pass, go vet clean.
2026-07-08 00:56:16 +02:00

57 lines
2.3 KiB
SQL

-- Migration 012: Client enrollment and compute entity provisioning
-- Adds provisioning tracking and client-specific lookup indexes.
-- Provisioning step tracker for LXC/VM/container creation.
-- Tracks individual steps within a provisioning execution so the client
-- can poll GET /provision/status for progress.
CREATE TABLE IF NOT EXISTS provisioning_steps (
id UUID PRIMARY KEY,
entity_id UUID NOT NULL REFERENCES entities(id) ON DELETE CASCADE,
execution_id UUID NOT NULL REFERENCES executions(entity_id) ON DELETE CASCADE,
step_order INTEGER NOT NULL,
step_name TEXT NOT NULL,
status TEXT NOT NULL DEFAULT 'pending'
CHECK (status IN ('pending', 'running', 'ok', 'failed', 'skipped')),
started_at TIMESTAMPTZ,
finished_at TIMESTAMPTZ,
error_message TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
UNIQUE(entity_id, step_name)
);
CREATE INDEX IF NOT EXISTS idx_provisioning_steps_entity
ON provisioning_steps (entity_id, step_order);
CREATE INDEX IF NOT EXISTS idx_provisioning_steps_execution
ON provisioning_steps (execution_id);
-- Fast lookup for client entities by slug prefix + type.
-- Supports whoami(hostname) and GET /clients/{slug} lookups.
CREATE INDEX IF NOT EXISTS idx_entities_slug_type_machine
ON entities (slug, type)
WHERE type IN ('workstation', 'standalone-server', 'proxmox-host');
-- Track client enrollment state separately from entity state.
-- An entity may be in provisioning for infrastructure reasons while
-- enrollment (age key, Infisical identity) is complete.
ALTER TABLE entities ADD COLUMN IF NOT EXISTS enrolled_at TIMESTAMPTZ;
ALTER TABLE entities ADD COLUMN IF NOT EXISTS enrolled_by UUID;
-- Context version tracking — incremented when agent files change,
-- so clients can poll GET /context?since= efficiently.
CREATE TABLE IF NOT EXISTS context_version (
singleton BOOLEAN PRIMARY KEY DEFAULT true
CHECK (singleton = true),
version BIGINT NOT NULL DEFAULT 0,
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
INSERT INTO context_version (version) VALUES (0)
ON CONFLICT (singleton) DO NOTHING;
-- List of files included in the agent context bundle.
CREATE TABLE IF NOT EXISTS context_files (
path TEXT PRIMARY KEY,
hash TEXT NOT NULL,
last_changed TIMESTAMPTZ NOT NULL DEFAULT now()
);