provisioning-server/migrations/0007_auftragskatalog.sql
Thomas Stallinger eb73f2b6b7 feat: extend agent check-in with Auftragskatalog state, add report endpoint
Check-in now also returns "auftraege": the full present/absent state
of every catalog-eligible Merkmal (im_auftragskatalog = true) for the
device's backend, derived statelessly from device_merkmale rather than
just the workspace-resolved blueprints list, which stays untouched.
This is what lets a deselected Auftrag actually be reverted once the
corresponding Ansible role grows an absent branch (ADR-0010) - the
agent doesn't have that branch yet, so this is additive and inert
until it does.

Adds POST /api/v1/agent/report so the agent can write execution
results (applied/apply_failed/removed/remove_failed) back into
device_merkmal_events; selected/deselected is intentionally rejected
here since those are meant to come from wherever Auftrag selection
ends up being triggered, not from the agent itself.

Migration 0007 adds the backing tables (kategorien, device_merkmale,
device_merkmal_events) and the two new merkmale columns.

Verified against anode: checkin toggles present/absent correctly
after inserting a device_merkmale row, report endpoint accepts valid
entries and rejects unknown merkmale / non-agent event types / bad
secrets, and the written event round-trips through device_merkmal_events
correctly as jsonb.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-04 09:17:19 +02:00

53 lines
1.3 KiB
PL/PgSQL

BEGIN;
CREATE TABLE kategorien (
id UUID PRIMARY KEY,
key TEXT NOT NULL UNIQUE,
name TEXT NOT NULL,
description TEXT,
sort_order INTEGER NOT NULL DEFAULT 0
);
ALTER TABLE merkmale ADD COLUMN kategorie_id UUID
REFERENCES kategorien(id)
ON DELETE SET NULL;
ALTER TABLE merkmale ADD COLUMN im_auftragskatalog BOOLEAN NOT NULL DEFAULT FALSE;
CREATE TABLE device_merkmale (
id UUID PRIMARY KEY,
device_id UUID NOT NULL
REFERENCES devices(id)
ON DELETE CASCADE,
merkmal_id UUID NOT NULL
REFERENCES merkmale(id)
ON DELETE RESTRICT,
aktiv BOOLEAN NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
UNIQUE (device_id, merkmal_id)
);
CREATE TABLE device_merkmal_events (
id UUID PRIMARY KEY,
device_id UUID NOT NULL
REFERENCES devices(id)
ON DELETE CASCADE,
merkmal_id UUID NOT NULL
REFERENCES merkmale(id)
ON DELETE RESTRICT,
event_type TEXT NOT NULL
CHECK (event_type IN (
'selected',
'deselected',
'applied',
'apply_failed',
'removed',
'remove_failed'
)),
detail JSONB,
occurred_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
);
COMMIT;