Skip to content

feat: delete capabilities — delete child, transaction, spending, investment, parent - #8

Open
isaJrKai wants to merge 2 commits into
mainfrom
fix/delete-capabilities
Open

feat: delete capabilities — delete child, transaction, spending, investment, parent#8
isaJrKai wants to merge 2 commits into
mainfrom
fix/delete-capabilities

Conversation

@isaJrKai

@isaJrKai isaJrKai commented Jul 1, 2026

Copy link
Copy Markdown
Owner

What this adds

Adds 8 delete functions to the mutations API. Parents can now remove data they created — they're in control.

Delete functions

Function What it does Cascades?
deleteTransaction Removes a single transaction No
deleteSpendingEntry Removes a spending entry No
closeInvestment Marks investment as "closed" No (preserves audit trail)
deleteInvestment Permanently deletes investment Yes — related transactions
deleteChild DESTRUCTIVE — deletes child + all their data Yes — accounts, transactions, spending, investments, tokens, goals
deleteParent Deletes parent profile Yes — spending entries, goals
deleteSpendingCategory Removes a spending category No
resetFamilyData NUCLEAR — deletes ALL family data Yes — everything except the User account

Security

All delete functions verify familyId ownership before operating. A user cannot delete another family's data — the query returns "not found or access denied" if the familyId doesn't match.

Files changed (3 files)

  • src/lib/db-queries.ts — 8 new delete functions
  • src/app/api/mutations/route.ts — 8 new action cases
  • src/lib/mutations.ts — 8 new client-side functions

Verification

  • npx tsc --noEmit — clean
  • npx eslint — clean

Vercel env vars

None needed.

Deployment risk

Zero downtime. These are new API endpoints — existing functionality is unaffected. The UI to trigger these doesn't exist yet (Phase 3).

Depends on

PR #7 (multi-family isolation) — this branch is built on top of PR #7 for familyId scoping. Merge PR #7 first, then this one.

Next phase

Phase 3 (PR #9): Delete UI — delete buttons on cards, confirmation modals (two-step for destructive actions), "Danger Zone" section in settings.

Planned Founder added 2 commits July 1, 2026 16:45
Adds familyId to all 9 financial models (Child, ParentProfile, Account,
Transaction, SpendingCategory, SpendingEntry, Investment,
TokenLedgerEntry, Goal). Each new signup gets their own familyId.
All queries and mutations are scoped by familyId — families cannot
see or modify each other's data.

Changes:

1. Schema: add familyId column + index to 9 models. FamilySettings
   changes from singleton to per-family (keyed by familyId).
2. Migration: SQL to add columns, backfill existing data to founder's
   family, make NOT NULL, add indexes.
3. auth.ts: auto-generate familyId on signup + founder setup.
   getAuthUser() returns familyId.
4. db-queries.ts: getFullState(familyId) scopes all queries. All
   mutation functions accept familyId, include it in creates, and
   verify ownership on updates/deletes.
5. API routes: /api/state and /api/mutations pass familyId from
   getAuthUser() to all queries/mutations.

BEFORE MERGING: run the migration SQL on Neon.
…stment, parent

Adds 8 delete functions to the mutations API:

  - deleteTransaction — removes a single transaction
  - deleteSpendingEntry — removes a spending entry
  - closeInvestment — marks investment as closed (preserves audit trail)
  - deleteInvestment — permanently deletes investment + related transactions
  - deleteChild — DESTRUCTIVE: cascades to all child's data (accounts,
    transactions, spending, investments, tokens, goals)
  - deleteParent — cascades to spending entries + goals
  - deleteSpendingCategory — removes a spending category
  - resetFamilyData — NUCLEAR: deletes ALL family data, keeps User account

All delete functions verify familyId ownership before operating. A user
cannot delete another family's data.

Also adds corresponding client-side functions in src/lib/mutations.ts
so the frontend can call these via persistMutation().

Phase 3 (next PR) will add the UI: delete buttons on cards, confirmation
modals, and a Danger Zone section in settings.
@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@isaJrKai, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 11 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5bcb5a95-e6fd-4d03-9d71-66392fe8ded5

📥 Commits

Reviewing files that changed from the base of the PR and between 7053878 and 10ebb16.

📒 Files selected for processing (8)
  • prisma/migrations/20260625010000_add_multi_family_isolation.sql
  • prisma/schema.prisma
  • src/app/api/child/state/route.ts
  • src/app/api/mutations/route.ts
  • src/app/api/state/route.ts
  • src/lib/auth.ts
  • src/lib/db-queries.ts
  • src/lib/mutations.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/delete-capabilities

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant