Repository navigation
fix: d1_migrations 守卫改内容判定(三处同源)+ 补回归用例 (ONE-476) - #151
Merged
Merged
Conversation
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.
一句话
d1_migrations守卫从「只看表存不存在」改为「看表里有没有本应用自己的迁移文件名」,三处同源(prepare 脚本 / prefixed 脚本新装分支 / 运行时detectTablePrefixConflict),并补 3 组共 5 条回归用例。子单 ONE-478,父单 ONE-476。改动
.github/scripts/d1-migration-files.mjs(新增):从apps/worker/migrations/*.sql现场枚举本应用 Wrangler 迁移文件名(一行一个),供两个部署脚本共用,脚本里没有任何硬编码清单。.github/scripts/d1-prepare-migrations.sh:unprefixed判定中d1_migrations一支改为has_app_migration_history()——查SELECT name FROM d1_migrations与本应用文件名集合求交,有交集才置unprefixed=true。_schema_migrations一支、其余分支、错误文案未动。.github/scripts/d1-prefixed-migrations.sh:新装分支守卫换成同一个has_app_migration_history(),与 prepare 同口径。apps/worker/src/lib/migrations.ts:新增WRANGLER_MIGRATION_FILES,值为getMigrations('').map(m => m.fileName)(复用既有fileName单源,不另起清单;新增 Wrangler 迁移只需在getMigrations()里加一条)。apps/worker/src/lib/migrations-runner.ts:detectTablePrefixConflict()改为查d1_migrations的name与WRANGLER_MIGRATION_FILES求交。回归用例(规格 §3 的 1–6)
.github/scripts/test-d1-migrations.mjs:①外来d1_migrations(仅0001_other_app.sql/0002_other_app.sql)+TABLE_PREFIX=SL+ 无任何 SL 表 → prepare 输出mode=prefixed,prefixed 脚本计划并执行schema_v1 schema_v2、_SL_schema_migrations两行齐全、assertOwnIndexes('SL')通过、他表快照与d1_migrations内容前后不变;②d1_migrations含0001_init.sql/0002_token_version.sql→ prepare 仍以/unprefixed schema/中止,prefixed 脚本同样拒绝,且未建出任何 SL 表。apps/worker/test/migrations-runner.test.ts:④外来d1_migrations+prefix=SL+ 无 SL 表 → 不抛TablePrefixConflict,正常建出_SL_schema_migrations两行;⑤d1_migrations含0001_init.sql→ 仍抛TablePrefixConflict(/unprefixed schema/);⑥WRANGLER_MIGRATION_FILES与apps/worker/migrations/目录实际文件集合相等(漂移即红)。自测证据(红 → 绿)
红:把三处守卫临时改回「只看存在」后跑新用例 ——
回归:仅外来 d1_migrations(别家文件名)+ prefix=SL→ FAIL(Command failed: d1-prepare-migrations.sh,即线上误杀)回归:仅外来 d1_migrations(别家文件名)+ SL 表全删→ FAIL(同上)绿(本 commit,本地跑):
node --test .github/scripts/test-d1-migrations.mjs→ 13/13 passpnpm test(worker vitest 等价,node:test)→ 110/110 passpnpm check(biome)→ clean;shellcheck .github/scripts/*.sh→ cleanpnpm typecheck→ 2/2 successful;pnpm build→ 2/2 successful未做:未接触任何线上 D1 / KV / Secrets,未改
TABLE_PREFIX=SL双边配置,未改迁移内容与账本结构。Closes ONE-478(父单 ONE-476)