fix(projects): delete chapter assignments across all project units#204
Conversation
deleteByProject selected a single project_unit with limit(1) and deleted only that unit's chapter assignments, so a project with more than one unit would orphan the others. createProject currently makes exactly one unit, so this is latent — but the cleanup shouldn't assume a 1:1 project<->unit relationship. Replace the select-one + delete-by-id (two round-trips in a transaction) with a single DELETE whose WHERE uses a project_units subquery, covering all of the project's units. One round-trip, no transaction needed, and the empty case returns deletedCount: 0 naturally. From the code audit (untracked follow-up).
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
ChangesProject chapter assignment deletion
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai full review |
✅ Action performedFull review finished. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a latent data-integrity issue in the projects domain by ensuring chapter assignments are deleted for all project units under a project, rather than only one unit.
Changes:
- Replaced a transaction-based “select one project unit + delete by that unit id” flow with a single
DELETE ... WHERE project_unit_id IN (subquery)statement. - Ensures multi-unit projects don’t leave orphaned chapter assignments and returns an accurate
deletedCount.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
From the code audit (untracked follow-up).
Problem
deleteByProjectselected a single project unit with.limit(1)and deleted only that unit's chapter assignments. If a project ever has more than oneproject_unit, the other units' assignments are silently orphaned.createProjectcurrently makes exactly one unit, so this is latent today — but the cleanup shouldn't assume a 1:1 project↔unit relationship.Fix
Replace the select-one + delete-by-id (two round-trips, in a transaction) with a single statement that deletes assignments for all of the project's units via a subquery — effectively:
One round-trip, no transaction needed (single atomic statement), and the empty case returns
deletedCount: 0naturally.Test plan
npm run typechecknpm run lintnpm run test— 80/80 passSummary by CodeRabbit