Skip to content

fix(data): include missing tables in account deletion handler#1758

Merged
Priyanshu-byte-coder merged 1 commit into
Priyanshu-byte-coder:mainfrom
nyxsky404:fix/account-deletion-orphaned-rows
May 31, 2026
Merged

fix(data): include missing tables in account deletion handler#1758
Priyanshu-byte-coder merged 1 commit into
Priyanshu-byte-coder:mainfrom
nyxsky404:fix/account-deletion-orphaned-rows

Conversation

@nyxsky404
Copy link
Copy Markdown
Contributor

Summary

The account deletion handler (DELETE /api/user/data-export) was missing 4 tables from its cleanup routine, leaving orphaned rows in the database after a user deleted their account.

Closes #1756


Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactor / code cleanup

Changes Made

  • Added webhook_deliveries deletion via webhook_id lookup (this table lacks a direct user_id column, so IDs are resolved from webhook_configs first)
  • Added notifications, ai_insights, and data_export_audit to the direct-deletion list
  • Reordered tables to respect foreign key constraints (children deleted before parents)
  • Fixed inconsistent indentation on the tablesToDelete array

Tables added:

Table Relationship Why it was missed
notifications user_id FK Not in original list
ai_insights user_id FK Not in original list
data_export_audit user_id FK Not in original list
webhook_deliveries webhook_id FK → webhook_configs Indirect relationship via parent table

How to Test

  1. Create a test user account via GitHub OAuth sign-in
  2. Generate some data: create goals, trigger notifications, use AI insights, configure a custom webhook
  3. Navigate to Settings → Delete Account
  4. Type "DELETE" and confirm
  5. Verify in Supabase dashboard that no rows remain in notifications, ai_insights, data_export_audit, or webhook_deliveries for that user
  6. Confirm the user row itself is also removed from users

Screenshots (if UI change)

N/A — backend-only change.


Checklist

  • Linked issue in summary
  • npm run lint passes locally
  • No TypeScript errors (npm run type-check)
  • Self-reviewed the diff
  • Added/updated tests if applicable

Accessibility Checklist

N/A — no UI changes.


Additional Notes

The webhook_deliveries table uses webhook_id (not user_id) as its foreign key, so it cannot be deleted with a simple .eq("user_id", ...) call. The fix first queries webhook_configs for the user's webhook IDs, then deletes matching deliveries before removing the configs themselves. The if (webhookIds.length > 0) guard prevents an empty .in() call which could have unexpected behavior in some PostgREST versions.

The DELETE handler in /api/user/data-export was missing notifications,
ai_insights, data_export_audit, and webhook_deliveries tables. This
left orphaned rows in the database after a user deleted their account.

- Add webhook_deliveries deletion (resolved via webhook_id lookup since
  it lacks a direct user_id column)
- Add notifications, ai_insights, and data_export_audit to the
  direct-deletion list
- Reorder tables to respect foreign key constraints (children first)

Closes Priyanshu-byte-coder#1756
@vercel
Copy link
Copy Markdown

vercel Bot commented May 31, 2026

@nyxsky404 is attempting to deploy a commit to the PRIYANSHU DOSHI's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added gssoc26 GSSoC 2026 contribution type:bug GSSoC type bonus: bug fix labels May 31, 2026
@github-actions
Copy link
Copy Markdown

GSSoC Label Checklist 🏷️

@Priyanshu-byte-coder — please apply the appropriate labels before merging:

Difficulty (pick one):

  • level:beginner — 20 pts
  • level:intermediate — 35 pts
  • level:advanced — 55 pts
  • level:critical — 80 pts

Quality (optional):

  • quality:clean — ×1.2 multiplier
  • quality:exceptional — ×1.5 multiplier

Validation (required to score):

  • gssoc:approved — counts for points
  • gssoc:invalid / gssoc:spam / gssoc:ai-slop — does not score

Type labels (type:*) are auto-detected from files and title. Review and adjust if needed.
Points formula: (difficulty × quality_multiplier) + type_bonus

@Priyanshu-byte-coder Priyanshu-byte-coder added level2 GSSoC Level 2 - Medium complexity (25 points) gssoc:approved GSSoC: PR approved for scoring labels May 31, 2026
@Priyanshu-byte-coder Priyanshu-byte-coder merged commit f03c7f2 into Priyanshu-byte-coder:main May 31, 2026
4 of 5 checks passed
@github-actions
Copy link
Copy Markdown

🎉 Merged! Thanks for contributing to DevTrack.

If the project has been useful to you, a ⭐ star on the repo is the easiest way to support it — it helps DevTrack get discovered by more developers.

Keep an eye on open issues for your next contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved GSSoC: PR approved for scoring gssoc26 GSSoC 2026 contribution level2 GSSoC Level 2 - Medium complexity (25 points) type:bug GSSoC type bonus: bug fix

Projects

None yet

2 participants