Repository navigation
feat(worker): TABLE_PREFIX 三态语义 + 防静默切换 (ONE-201) - #145
Merged
Merged
Conversation
- getTablePrefix 三态:未配置 → 默认 enotify(enotify_);自定义 → 补尾 _;显式空串 → 无前缀;默认常量与解析集中 types.ts 一处 - 中间件消除第二解析点,改为校验解析后前缀(空串合法) - runSetup 前置 detectTablePrefixes 探测 sqlite_master,检测到异前缀已初始化 schema 时 409 PREFIX_CONFLICT 中止(含旧无前缀 schema 具名指引),绝不自动重建表;成功返回 effectivePrefix - SetupResult 失败分支补 error 字段(适配 web setupApi.run 的 body.error 提取) - setup/admin 路由非成功态显式 c.json(result, 409) - CI deploy.yml 三态注入:vars 未设/空 → enotify;none → 空串;其他原样 - MockD1 补全 sqlite_master 全表扫描;存量测试适配 effectivePrefix;新增 prefix.test.ts(三态解析 / 冲突中止 / detectTablePrefixes) - README.md / README.en.md / CLAUDE.md 更新三态语义、CI none 约定与升级警告
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景(ONE-201 / ONE-210)
把 eNotify 表前缀语义从「方案 2」改造为「方案 1」三态。按 ONE-208 提案 + ONE-209 Tony 评审定案的冻结契约实现,4 条 should-fix 已全部落地。
改动
三态解析(唯一解析点)
worker/src/types.ts:DEFAULT_TABLE_PREFIX = "enotify";Env.TABLE_PREFIX改为可选;getTablePrefix三态——未配置(undefined/null)→enotify_;自定义非空 → 现行规范化(补尾_,不放宽);显式空串""→ 无前缀。worker/src/index.ts:中间件消除c.env.TABLE_PREFIX || ""第二解析点,改为校验getTablePrefix解析结果(空串合法,非法字符仍 500)。防静默切换
worker/src/lib/setup.ts:runSetup先全表扫描sqlite_master,detectTablePrefixes(导出纯函数)识别已初始化 schema 的前缀(≥4 张核心表且含users);与解析前缀不一致 → 返回 409PREFIX_CONFLICT(error+message+resolvedPrefix+detectedPrefixes),绝不自动按新前缀建表。旧无前缀 schema + 未配置 → 具名指引TABLE_PREFIX=none。effectivePrefix(新装与存量升级均适用)。routes/setup.ts、routes/admin.ts:非成功态显式c.json(result, 409)。CI 三态
.github/workflows/deploy.yml:vars 未设/空 → 注入enotify;none→ 注入空串;其他原样。与运行时解析一致(已本地模拟三种注入验证)。测试
worker/test/prefix.test.ts(21 用例):三态解析单测(undefined/null/自定义/补尾/空串)、detectTablePrefixes纯函数(前缀识别/无前缀 schema/阈值 4/需含 users/无关表不误判/大小写)、冲突中止(异前缀 409、旧无前缀 409 具名指引、显式空串遇异前缀 409、匹配前缀成功、空库默认初始化、无关表不冲突、admin 路由 409、直接调用返回体形状、断言未静默建表)。worker/test/helpers.ts:MockD1.exec补全sqlite_master无条件全表扫描。effectivePrefix(setup/admin/migrations)。文档
README.md/README.en.md/CLAUDE.md:三态语义 + 默认值enotify+ CInone约定 + 老部署升级警告。自测
pnpm test:10 个测试文件、127 个用例全部通过(含新增 21 个)。pnpm typecheck(web + worker)、pnpm lint、pnpm format:check全绿。"enotify";none→"";eNotify→"eNotify"。生产影响
线上实际生效前缀
eNotify(规范化eNotify_)为自定义态,升级后解析结果不变,无静默切换风险;防静默切换仅对「从未配置过前缀的老部署」触发拦截。