-- 节点事件。event CHECK 预置最终全集（含 ip_rotated，使 000008 的 enum 扩展在 SQLite 成为 no-op）。
CREATE TABLE node_events (
  id      INTEGER PRIMARY KEY AUTOINCREMENT,
  node_id INTEGER NOT NULL,
  event   TEXT NOT NULL CHECK (event IN ('provisioned','probe_pass','probe_fail','marked_up','draining','blocked_suspect','blocked_confirmed','replaced','destroyed','ip_rotated')),
  detail  TEXT NULL,                               -- JSON
  at      DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  FOREIGN KEY (node_id) REFERENCES nodes(id)
);
CREATE INDEX idx_node_events_node_at ON node_events (node_id, at);

-- 目录版本单例
CREATE TABLE directory_version (
  id      INTEGER PRIMARY KEY DEFAULT 1 CHECK (id = 1),
  version INTEGER NOT NULL
);
