Skip to content

nav 场景维度·后端实现:scenes 迁移 + DTO + 场景/分类接口(引用 #16 契约) - #31

Merged
todosdev[bot] merged 3 commits into
mainfrom
tds/conv-01a1afc9-e20a-758b-8ed8-9bb5f498b9e1
Nov 6, 2026
Merged

todosdev[bot] merged 3 commits into
mainfrom
tds/conv-01a1afc9-e20a-758b-8ed8-9bb5f498b9e1

Conversation

@todosdev

@todosdev todosdev Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds the orthogonal scenes dimension: a schema_v2 migration creates scenes with a single default 通用 scene, adds categories.scene_id, and backfills existing categories.
  • Public/private/admin DTOs now carry scenes and category sceneId, with admin CRUD/reorder endpoints and whole-category scene moves.
  • Deleting a non-default scene moves its categories and links into the default scene inside one db.batch transaction; the API contract is documented and admin handlers run the lazy schema guard.

Changes

  • Migration (worker/src/lib/migrations.ts): schema_v2 adds the scenes table, partial unique index on is_default = 1, seeded default scene, categories.scene_id + index, and the legacy backfill. Uses the existing t()/idx() prefix templates.
  • DTOs & site data (worker/src/types.ts, worker/src/services/site-data.ts, worker/src/routes/public.ts, worker/src/routes/private.ts): new SceneDto / AdminSceneDto, sceneId on category DTOs, scenes[] on SiteDataDto. Public/private still apply existing visibility rules and return every scene; NULL/dangling scene ids normalize to the default scene.
  • Queries (worker/src/db/queries/content.ts): scene list/find/insert/update, next sort-order helpers, and transactional deleteSceneMovingCategories.
  • Admin API (worker/src/routes/admin.ts): GET/POST/PUT/DELETE /api/admin/scenes, POST /api/admin/scenes/reorder; category POST/PUT accept sceneId (PUT moves the whole category); name/icon/sort validation; isDefault read-only; default scene returns 400 on delete. Scene-aware handlers call ensureSchema so a Worker-only deploy does not 500 before /api/private triggers the upgrade.
  • Tests (worker/test/): SqliteD1.batch transaction stand-in, 20+ scene/API/DTO tests, a schema_v1-only admin upgrade regression, and updated migration ledger expectations. No web/ changes.
  • Docs (docs/api-contract.md): documents the scene data model, semantics, DTOs, endpoints, delete behaviour, and category move sorting.

Deployment note: schema_v2 is applied lazily by the first request after deploy. This is a production schema write; take a d1 export backup and get approval before deploying.

Testing

  • pnpm --filter worker test — 13 files, 177 tests passed.
  • pnpm test — worker 177 + web 136 tests passed.
  • pnpm typecheck, pnpm format:check, pnpm lint (exit 0; only pre-existing web warnings), pnpm build — all passed.
  • Regression check: the schema_v1-only admin test returned 500 without the new ensureSchema guard and 200 once it was restored; it also asserts the ledger becomes schema_v1, schema_v2 and the legacy category is backfilled.
  • CI Validate on head 75c7f19: success (run 42195151707).

Todos added 3 commits November 6, 2026 15:42
Add schema_v2 (scenes table, default 通用 seed, categories.scene_id,
backfill), SceneDto/AdminSceneDto plus sceneId on category DTOs, and the
admin scenes CRUD/reorder endpoints with move-on-delete in one db.batch
transaction. Covers DTO normalisation, validation and end-to-end tests.
Sync docs/api-contract.md with the frozen v1.1 scene contract: schema_v2
data model and semantics, SceneDto/AdminSceneDto, sceneId on category
payloads, the admin scenes CRUD/reorder/delete behaviour, and moving a
whole category between scenes.
Run ensureSchema in the category/scene admin handlers so a Worker-only
deploy cannot 500 on `no such table: scenes` before /api/private triggers
the lazy upgrade. Add a schema_v1-only regression test.

When moving a category without an explicit sortOrder, append it to the
target scene (MAX+1), matching the delete-scene rule and avoiding
collisions; document the move semantics and correct the public/private
wording in docs/api-contract.md.
@todosdev
todosdev Bot merged commit 520cbc1 into main Nov 6, 2026
2 checks passed
@mapxn
mapxn deleted the tds/conv-01a1afc9-e20a-758b-8ed8-9bb5f498b9e1 branch November 8, 2026 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants