Repository navigation
部署流程:冒烟测试兼容 Bot Fight Mode + 带表前缀时自动执行迁移 - #120
Merged
todosdev[bot] merged 3 commits intoOct 17, 2026
Merged
Conversation
added 3 commits
October 17, 2026 21:12
- Add isolated local D1 tests for migration plans and shared database safety. - Test challenge handling and active-version checks without production access. Checkpoint: 30_Qk0mFgDFOpIHz4McVL
- Restore English text in README.md section 6 (Chinese stays in README.zh-CN.md). - Use non-colliding index names in the shared-DB test fixture and assert every migration index exists on the prefixed table; document the index-name collision. - Run shellcheck and the deploy-script tests in the CI workflow. Checkpoint: 7jPqyGVbPXMuvvXcSuaR7
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
TABLE_PREFIXis set, the deploy now applies prefixed migrations automatically before deploying the code. The migrations come from the same source asPOST /setup, and are recorded in_<prefix>_schema_migrationsin the same format as the setup route. Before, the deploy skipped migrations, so schema changes had to be applied by hand in the D1 console.userstable.Changes
apps/worker/src/lib/migrations.ts:getMigrations(prefix),tbl(),migrationsTable()andcreateMigrationsTableSql(), moved out ofroutes/setup.tsunchanged.routes/setup.tsnow imports them. The module has no imports and no TS-only syntax, so Node can load it directly..github/scripts/)d1-migrations.mjsimports the migrations module and prints the SQL for a prefix. It only allowsCREATE TABLE/INDEX IF NOT EXISTS,ALTER TABLE … ADDandINSERT OR IGNORE, and every statement must target a table with the app's prefix. Anything else aborts the deploy.d1-prefixed-migrations.shprints the migration history and the planned migrations, then applies only the pending ones.TABLE_PREFIXas the GitHub variable.SL_tables exist but have noschema_v1record.d1-prepare-migrations.shoutputsmode=prefixedwhenTABLE_PREFIXis set (previouslyskip). The unprefixed wrangler path is unchanged. It also acceptsD1_LOCATION=localfor testing.worker-table-prefix.shreads theTABLE_PREFIXplain-text binding from a Worker version. It fails if the binding is a secret, because the value can't be read back to compare.verify-deployment.shreads theversion_idthatwrangler deploywrites toWRANGLER_OUTPUT_FILE_PATH. It then checks, with retries, thatwrangler deployments status --jsonshows that version at 100%, and that itsTABLE_PREFIXmatches.smoke-test.shmakes one curl request per attempt so status, headers and body stay together.cf-mitigated: challengeproduces a::warning::.deploy.yml:apps/workerwithWRANGLER_OUTPUT_FILE_PATHset;CHECK_DB(the/api/configcheck) now also runs in prefixed mode;ci.ymlruns shellcheck on the deploy scripts and the deploy-script tests. They need no Cloudflare credentials.README.mdandREADME.zh-CN.mdnow describes:TABLE_PREFIXmust be a plain-text Worker variable matching the GitHub production variable;/setupas optional;Testing
node --test .github/scripts/test-d1-migrations.mjs .github/scripts/test-deploy-checks.mjs: all 17 tests pass locally. The D1 tests use a throwaway local D1 database.SELECTqueries ran.schema_v2pending: applies only v2, existing rows gettoken_version = 0, and a second run is a no-op.SL_*tables.SL_tables with no or empty history: the script refuses to run.userstable andZETA_*tables (schema, indexes and data) are unchanged in every scenario.SL_*table. A separate test reproduces the known index-name collision and shows this assertion catches it.cf-mitigated: challengewarns and still probes every path. A plain 403, a 500 (even with the challenge header), a 302, and a 200 with a bad config body all fail.wrangler): passes when the new version serves 100%. Fails when the old version is still active, when the new version serves only part of the traffic, or when the prefix doesn't match.actionlint(includes shellcheck),shellcheck .github/scripts/*.sh,pnpm check,pnpm typecheck --forceandpnpm build --forceall pass._SL_schema_migrations, the first prefixed run should printPlanned migrations: noneand write nothing. Nobody has checked the table's contents yet. Ifschema_v1is missing, the script refuses to run rather than guessing.SL_*tables, so nothing is affected today. The risk is a second shortlink install, or another app using the same index name, in the same database. Fixing it would mean a new migration that adds prefixed index names, which the user can decide on.TABLE_PREFIXmust be a plain-text variable, not a secret, and match the GitHubproductionvalueSL.CLOUDFLARE_API_TOKENneeds D1 edit plus Worker edit/version-read scope.