Files
pangolin/server/migrations/mysql/000005_providers_nodes.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

34 lines
1.7 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- VPS 厂商池(先建,nodes 有 FK 引用)
CREATE TABLE providers (
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(64) NOT NULL,
api_kind VARCHAR(32) NOT NULL, -- 开通自动化所用 API 适配器
regions JSON NOT NULL,
pool ENUM('consumable','premium') NOT NULL,
enabled BOOLEAN NOT NULL DEFAULT TRUE,
note VARCHAR(255) NULL -- 凭证不入库,存独立 secrets 管理
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- 节点:蓝本 nodes 表 + 拓扑/生命周期扩展字段
CREATE TABLE nodes (
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
uuid CHAR(36) NOT NULL UNIQUE,
region VARCHAR(8) NOT NULL, -- HK / JP / SG / US…
name_zh VARCHAR(64) NOT NULL,
name_en VARCHAR(64) NOT NULL,
role ENUM('entry','relay','exit') NOT NULL DEFAULT 'entry',
tier ENUM('free','pro') NOT NULL, -- 消耗品池 / 精品池
endpoint VARCHAR(255) NOT NULL, -- ip:portREALITY
hy2_port INT NULL, -- Hysteria2 端口跳跃区间起点
reality_pbk VARCHAR(64) NOT NULL,
reality_sni VARCHAR(128) NOT NULL, -- 伪装目标 SNI
provider_id BIGINT UNSIGNED NOT NULL,
tags JSON NULL,
status ENUM('provisioning','probing','up','draining','down','destroyed')
NOT NULL DEFAULT 'provisioning', -- 生命周期状态机
weight INT NOT NULL DEFAULT 100,
created_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
FOREIGN KEY (provider_id) REFERENCES providers(id),
INDEX idx_status_tier (status, tier)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;