feat(db): add MySQL migrations 000001-000007 covering all 12 tables + seed [tsk_paiqu21eZIuw]

- 000001: users + devices(账户 / 设备,含 argon2id pw_hash、dp_uuid)
- 000002: plans + subscriptions(套餐口径来自 design/CLAUDE.md §7)
- 000003: code_batches + codes(SHA-256 code_hash,明文不入库)
- 000004: usage_daily + audit_log(最小数据原则 + JSON meta)
- 000005: providers + nodes(providers 先建,nodes FK 引用)
- 000006: node_events(9 值 ENUM)+ directory_version(CHECK id=1,MySQL ≥ 8.0.16)
- 000007: plans 三行 seed + directory_version(1,1),ON DUPLICATE KEY UPDATE 保可重入

所有表 ENGINE=InnoDB DEFAULT CHARSET=utf8mb4,时间列 DATETIME(6),
主键 BIGINT UNSIGNED AUTO_INCREMENT + 对外 uuid CHAR(36) UNIQUE。
每对 down 文件逆序 DROP(子表先于父表)。

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-06-13 01:28:01 +08:00
parent a642bf16a2
commit b4114c93ee
14 changed files with 177 additions and 0 deletions
@@ -0,0 +1,33 @@
-- 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;