-- 节点事件：状态迁移与判封依据（探针明细在 Redis，结论落库）
CREATE TABLE node_events (
  id      BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  node_id BIGINT UNSIGNED NOT NULL,
  event   ENUM('provisioned','probe_pass','probe_fail','marked_up','draining',
               'blocked_suspect','blocked_confirmed','replaced','destroyed') NOT NULL,
  detail  JSON NULL,                               -- 探针命中率、判封依据等
  at      DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
  FOREIGN KEY (node_id) REFERENCES nodes(id),
  INDEX idx_node_at (node_id, at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- 目录版本：nodes 任何变更 bump，客户端 if_version 灰度
-- CHECK (id = 1) 需要 MySQL >= 8.0.16
CREATE TABLE directory_version (
  id      TINYINT PRIMARY KEY DEFAULT 1,
  version BIGINT UNSIGNED NOT NULL,
  CHECK (id = 1)
) ENGINE=InnoDB;
