Repository navigation
ONE-203: three-state TABLE_PREFIX + silent-switch guard + CI none convention - #141
Merged
Merged
Conversation
…vention Implement the frozen three-state prefix semantics with a single source of truth (apps/worker/src/lib/table-prefix.ts): - undefined → default 'sl'; '' → no prefix; custom value → as-is (case preserved, [^a-zA-Z0-9_] stripped) - db.ts tbl() and migrations.ts tbl() both resolve through the shared helper - migrations-runner resolves the effective prefix and aborts (409 via setup / admin routes) when the database already holds a schema under a different prefix — never silently switches - deploy workflow resolves vars.TABLE_PREFIX three-state (unset/empty → sl, none → '', else as-is) and passes the resolved value to all scripts - d1-prepare/d1-prefixed/worker-table-prefix/verify-deployment scripts adapted; an unset Worker binding now reads as the default 'sl' - tests for the three-state resolution, the silent-switch guard, the none convention and the deploy scripts; docs updated (README en/zh, CLAUDE.md)
…d 2) Address ONE-206 review blocking items — the guard treated "any foreign table" as a shortlink schema switch, and "already-initialised under the current prefix" as a conflict: - The shared D1 database carries other apps' tables (bare users, ZETA_*, eNotify_*) and wrangler's d1_migrations. A bare `users` table alone is no longer a signal; unprefixed shortlink is recognised by `_schema_migrations` (containing schema_v1) or `d1_migrations`. - When the current prefix is already initialised (`_<prefix>_schema_migrations` / `<prefix>_users`), migration is incremental and allowed — never aborted. - Prefixed shortlink detection for the explicit-empty case now uses `^_(.+)_schema_migrations$` and, in the runtime, the intersection of shortlink-unique tables (passkeys + links + totp_used) — no single-table matching. - Restore the shared-DB test fixture's bare `users` and add regression tests for both boundaries. - Frontend: map the setup/admin 409 to a localized message that passes through the backend's actionable TABLE_PREFIX guidance (was falling into generic).
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.
Summary
Implements the frozen three-state
TABLE_PREFIXsemantics for shortlink (父单 ONE-203 / 实现子单 ONE-205).apps/worker/src/lib/table-prefix.ts:DEFAULT_TABLE_PREFIX = 'sl',resolveTablePrefix(),tbl().sl; explicit''→ no prefix; custom value → as-is (case preserved,[^a-zA-Z0-9_]stripped).migrations-runner.tsaborts withTablePrefixConflictError(surfaced as HTTP 409 by setup/admin routes) when the DB already holds an initialized schema under a different prefix. Deploy scripts (d1-prepare-migrations.sh/d1-prefixed-migrations.sh) mirror the guard.noneconvention: newresolve-table-prefix.mjsresolvesvars.TABLE_PREFIX— unset/empty →sl,none→'', else as-is — anddeploy.ymlpasses the resolved value to every step that uses it.worker-table-prefix.shnow printsslfor an unset Worker binding;verify-deployment.shcompares literally (case-sensitive, no folding) so productionSLis not confused withsl.none-convention tests; README (en/zh) and CLAUDE.md updated with the three-state semantics + defaultsl+noneconvention + upgrade warning.Test evidence (local)
pnpm check— OK (108 files, no issues)pnpm typecheck— 2 packages successfulpnpm test— web 54 pass / worker 83 pass, 0 failshellcheck .github/scripts/*.sh— cleannode --test .github/scripts/test-d1-migrations.mjs .github/scripts/test-deploy-checks.mjs— 24 pass, 0 failpnpm build— 2 packages successfulNotes
wrangler rollbackthe Worker version; tables staySL_*.TABLE_PREFIX=SL,_SL_schema_migrationswith schema_v1/v2) is the "explicitly configured" branch — effective prefix unchanged.