Files
pangolin/server/migrations/mysql/000006_node_events_dirver.up.sql
T
wangjia f3471ae139 feat(server/db): 数据层多库支持(1/4)— 连接分派 + 双方言迁移管线
- config 增 DB_DRIVER(mysql 默认 | sqlite);DSN 对 sqlite 为文件路径
- db.OpenDriver 按驱动分派:sqlite 用 modernc(纯 Go 免 CGO)+ WAL/
  busy_timeout/foreign_keys/_txlock=immediate;mysql 路径不变
- store.Open 分派;mysql 保留 UTC/collation 断言,sqlite 跳过
- 迁移拆 migrations/{mysql,sqlite}/ 双套,embed 双 FS,migrate 按驱动选源
  与 golang-migrate 驱动;修复 m.Close() 误关调用方 *sql.DB 的坑
- cmd/migrate 串入 DB_DRIVER;集成测试 MigrateUp 签名更新
- 新增 SQLite 时间往返 smoke 测试与端到端迁移测试(免 docker)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-18 00:01:03 +08:00

20 lines
899 B
SQL

-- 节点事件:状态迁移与判封依据(探针明细在 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;