Repository navigation
nav 场景维度·后端实现:scenes 迁移 + DTO + 场景/分类接口(引用 #16 契约) - #31
Merged
todosdev[bot] merged 3 commits intoNov 6, 2026
Merged
Conversation
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.
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
schema_v2migration createssceneswith a single default 通用 scene, addscategories.scene_id, and backfills existing categories.sceneId, with admin CRUD/reorder endpoints and whole-category scene moves.db.batchtransaction; the API contract is documented and admin handlers run the lazy schema guard.Changes
worker/src/lib/migrations.ts):schema_v2adds thescenestable, partial unique index onis_default = 1, seeded default scene,categories.scene_id+ index, and the legacy backfill. Uses the existingt()/idx()prefix templates.worker/src/types.ts,worker/src/services/site-data.ts,worker/src/routes/public.ts,worker/src/routes/private.ts): newSceneDto/AdminSceneDto,sceneIdon category DTOs,scenes[]onSiteDataDto. Public/private still apply existing visibility rules and return every scene; NULL/dangling scene ids normalize to the default scene.worker/src/db/queries/content.ts): scene list/find/insert/update, next sort-order helpers, and transactionaldeleteSceneMovingCategories.worker/src/routes/admin.ts):GET/POST/PUT/DELETE /api/admin/scenes,POST /api/admin/scenes/reorder; category POST/PUT acceptsceneId(PUT moves the whole category); name/icon/sort validation;isDefaultread-only; default scene returns 400 on delete. Scene-aware handlers callensureSchemaso a Worker-only deploy does not 500 before/api/privatetriggers the upgrade.worker/test/):SqliteD1.batchtransaction stand-in, 20+ scene/API/DTO tests, aschema_v1-only admin upgrade regression, and updated migration ledger expectations. Noweb/changes.docs/api-contract.md): documents the scene data model, semantics, DTOs, endpoints, delete behaviour, and category move sorting.Deployment note:
schema_v2is applied lazily by the first request after deploy. This is a production schema write; take ad1 exportbackup 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.ensureSchemaguard and 200 once it was restored; it also asserts the ledger becomesschema_v1, schema_v2and the legacy category is backfilled.Validateon head75c7f19: success (run42195151707).