b4114c93ee
- 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>
23 lines
974 B
SQL
23 lines
974 B
SQL
-- 激活码(App 内无支付,资金流外部化)
|
|
CREATE TABLE code_batches (
|
|
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
channel ENUM('store','tg','line','manual') NOT NULL,
|
|
created_by VARCHAR(64) NOT NULL,
|
|
note VARCHAR(255) NULL,
|
|
created_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
|
|
CREATE TABLE codes (
|
|
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
code_hash CHAR(64) NOT NULL UNIQUE, -- SHA-256;明文只出现一次
|
|
plan_id BIGINT UNSIGNED NOT NULL,
|
|
duration_days INT NOT NULL,
|
|
batch_id BIGINT UNSIGNED NOT NULL,
|
|
status ENUM('unused','redeemed','void') NOT NULL DEFAULT 'unused',
|
|
redeemed_by BIGINT UNSIGNED NULL,
|
|
redeemed_at DATETIME(6) NULL,
|
|
FOREIGN KEY (plan_id) REFERENCES plans(id),
|
|
FOREIGN KEY (batch_id) REFERENCES code_batches(id),
|
|
INDEX idx_status (status)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|