-- v2.0.0:邮件接收架构改造(docs/11) -- Cloudflare -> Email Worker -> Console;Node 从邮件链路中移除。 -- - nodes -> cloudflare_accounts(账号 = 已连接的 Cloudflare 账户,不再承载 Node 转发平面) -- - node_credentials -> worker_credentials(Email Worker 与 Console 的内部认证凭据) -- - nonces/oauth_states/domains/emails 的 node_id 语义改为 account_id(Console 账号) -- nonce 防重放:归属改为账号 ALTER TABLE nonces RENAME COLUMN node_id TO account_id; -- OAuth state 绑定账号 ALTER TABLE oauth_states RENAME COLUMN node_id TO account_id; -- 邮件归属账号 ALTER TABLE emails RENAME COLUMN node_id TO account_id; -- 域名归属账号(domains.node_id 存的是 Console 账号 id) ALTER TABLE domains RENAME COLUMN node_id TO account_id; -- 删除 Node 凭据表 DROP TABLE IF EXISTS node_credentials; -- 账号表更名并去除 Node 专属列 ALTER TABLE nodes RENAME TO cloudflare_accounts; ALTER TABLE cloudflare_accounts DROP COLUMN ingress_url; ALTER TABLE cloudflare_accounts DROP COLUMN ingress_secret_enc; ALTER TABLE cloudflare_accounts DROP COLUMN enrollment_token; ALTER TABLE cloudflare_accounts DROP COLUMN enrollment_expires_at; ALTER TABLE cloudflare_accounts DROP COLUMN credential_id; ALTER TABLE cloudflare_accounts DROP COLUMN version; ALTER TABLE cloudflare_accounts DROP COLUMN last_seen_at; -- 账号级 Email Worker 脚本名(worker_id 同时是 Worker -> Console 的身份 ID) ALTER TABLE cloudflare_accounts ADD COLUMN worker_id TEXT; -- 历史状态归一:心跳概念移除,online/offline 统一为 active UPDATE cloudflare_accounts SET status = 'active' WHERE status IN ('online', 'offline'); -- Email Worker -> Console 内部凭据:secret_hash 为摘要,secret_enc 为 AES-GCM 密文(HMAC 验签需要原文) CREATE TABLE IF NOT EXISTS worker_credentials ( id TEXT PRIMARY KEY, cloudflare_account_id TEXT NOT NULL, worker_id TEXT NOT NULL, -- Email Worker 脚本名,即请求方身份 secret_hash TEXT NOT NULL, secret_enc TEXT NOT NULL, secret_last4 TEXT NOT NULL, -- 展示用尾 4 位(明文 secret 不入库) status TEXT NOT NULL DEFAULT 'active', -- active | revoked created_at TEXT NOT NULL, revoked_at TEXT ); CREATE INDEX IF NOT EXISTS idx_worker_credentials_account ON worker_credentials(cloudflare_account_id); CREATE INDEX IF NOT EXISTS idx_worker_credentials_worker ON worker_credentials(worker_id);