CREATE TABLE IF NOT EXISTS cluster_nodes (
  id            UUID         PRIMARY KEY DEFAULT gen_random_uuid(),
  hostname      TEXT         NOT NULL,
  ip_address    TEXT,
  role          TEXT         NOT NULL DEFAULT 'worker',
  version       TEXT,
  api_url       TEXT,
  cpu_usage     NUMERIC(5,2),
  mem_used_mb   INTEGER,
  mem_total_mb  INTEGER,
  last_seen     TIMESTAMPTZ  NOT NULL DEFAULT NOW(),
  registered_at TIMESTAMPTZ  NOT NULL DEFAULT NOW(),
  metadata      JSONB,
  CONSTRAINT cluster_nodes_hostname_uq UNIQUE (hostname)
);
