feat: 成員/訂閱/方案/渠道 刪除(補齊 CRUD)#4
Merged
Merged
Conversation
Add hard-delete for users/subscriptions (cascade: payments + upload_tokens + R2 objects, with confirmation + audit) and guarded hard-delete for plans/channel_tags (409 when still referenced; soft-deactivate via active stays). List endpoints gain counts to drive the confirmation dialog + guarded front-end disable. Decisions from brainstorming.
4 tasks (TDD): cascade delete (users/subscriptions, +payments/upload_tokens/R2), guarded delete (plans/channel_tags, 409 when referenced), list dependency counts, and the front-end delete buttons + confirmation. Per the CRUD-delete spec.
DELETE /admin/users/:id and /admin/subscriptions/:id remove the entity plus its payments, upload_tokens, and R2 proof objects (child→parent; R2 cleanup guarded by env.BUCKET). Returns deletion counts and writes an audit log.
…eSubscription Wrap the multi-table cascade DELETEs in env.DB.batch() so a mid-sequence failure can't leave partial state; add workspace_id scoping to deleteSubscription's payment/ upload_token statements for defence-in-depth; tighten the test payment-count assertions.
DELETE /admin/plans/:id and /admin/channel-tags/:id hard-delete only when nothing references them (a subscription / a payment), else 409. Soft-deactivate via active remains. Writes an audit log.
…vate keeps history)
users gain subscription_count + payment_count; subscriptions gain payment_count; plans gain subscription_count; channel_tags gain usage_count. Drives the delete confirmation dialog and the guarded-delete front-end disable.
Each Manage list row gets a delete action. Members/subscriptions show a cascade confirmation with affected counts; plans/channel-tags disable delete while still referenced (guarded). Adds the api delete methods + count fields to the types.
… cascade Scope the dependency-count subqueries by workspace so the front-end disable parity matches the workspace-scoped delete guards (multi-workspace-safe). Add a cascade- delete test that verifies the R2 proof object is removed when R2 is configured.
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.
背景
後台原本只能新增/編輯成員與訂閱,無法刪除——嚴重的 CRUD 缺口。本 PR 補上四個實體的刪除能力。
CRUD 缺口 review(feature 2(b) 交付):掃過所有 admin 路由,缺 DELETE 的為 users / subscriptions / plans / channel_tags(payments 是交易紀錄,走狀態轉換不硬刪,刻意保留)。本 PR 對四者都補上。
docs/superpowers/specs/2026-06-07-crud-delete-design.mddocs/superpowers/plans/2026-06-07-crud-delete.md刪除語意
batch()原子化、workspace 限定、writeAudit、回傳刪除計數active=0停用);未參照才刪status='cancelled') 保留給「停收但留歷史」的情境。subscription_count/payment_count/usage_count,皆 workspace 關聯)→ 驅動前端確認框顯示「將刪除 N 筆」與 guarded 防呆(使用中則 disable)。驗證(CI 條件,無 .dev.vars)
pnpm -r typecheck✅pnpm -r test→ 177 passed (31 files) ✅(新增 cascade 計數、R2 有/無清理、guarded 409/放行、audit、list 計數等測試)pnpm -r build(web+admin)✅流程
每個 Task 經 implementer → spec 合規審查 → 程式品質審查(含修正迴圈:cascade 改 D1
batch()原子化、deleteSubscription 補 workspace scoping、plan-delete 409 訊息清晰化、count 子查詢 workspace 關聯、補 R2-present cascade 測試),最後整體 review(Ready to merge)。🤖 Generated with Claude Code