-- Fleet automation: metric-driven rules. When a node's metric crosses a threshold -- for a sustained window, fire an action (drain a hot node, bring one back, alert). -- A null node_id applies the rule to every node in the workspace. Paired with the -- metrics-aware placement (draining nodes stop receiving new agent workloads). CREATE TABLE node_rules ( id UUID PRIMARY KEY, workspace_id UUID NOT NULL REFERENCES workspaces (id) ON DELETE CASCADE, node_id UUID REFERENCES nodes (id) ON DELETE CASCADE, name TEXT NOT NULL, enabled BOOLEAN NOT NULL DEFAULT true, metric TEXT NOT NULL, -- cpu_pct | mem_pct | disk_pct | gpu_pct | temp_max | load1 op TEXT NOT NULL, -- '>' | '<' | '>=' | '<=' threshold DOUBLE PRECISION NOT NULL, for_seconds INTEGER NOT NULL DEFAULT 60, action JSONB NOT NULL, -- {"type":"drain"|"undrain"|"alert"} last_fired_at TIMESTAMPTZ, created_at TIMESTAMPTZ NOT NULL DEFAULT now() ); CREATE INDEX node_rules_ws ON node_rules (workspace_id);