Skip to content

Unify attendee dependent-row purges across single and orphan paths - #1821

Merged
stefan-burke merged 2 commits into
mainfrom
split/attendee-purge
Jul 14, 2026
Merged

Unify attendee dependent-row purges across single and orphan paths#1821
stefan-burke merged 2 commits into
mainfrom
split/attendee-purge

Conversation

@stefan-burke

@stefan-burke stefan-burke commented Jul 14, 2026

Copy link
Copy Markdown
Member

Before this change, the single-attendee delete path (in deleteAttendee) and the orphan-attendee purge path maintained two separate lists of the tables that link to an attendee. They had drifted: the orphan list was missing service_costs and handled it with a separate hand-written statement, while the single-delete path carried the full five-table list inline. Two parallel implementations of the same "delete an attendee's dependent rows" step is exactly the kind of duplication the project avoids.

What changed

I extracted one shared list of dependent-row targets and one helper that builds the delete statements for any set of attendee ids:

  • DEPENDENT_ROW_TARGETS in src/shared/db/attendees/delete.ts lists all five tables with their linking column: processed_payments, attendee_answers, listing_attendees, system_notes (all keyed by attendee_id), and service_costs (keyed by servicing_attendee_id).
  • attendeeDependentDeleteStatements(attendeeIds) builds the DELETE FROM ... WHERE ... IN (...) statements for that list, taking a single { sql, args } so the same helper works for one id ({ sql: "?", args: [id] }) and for the orphan subquery ({ sql: ORPHAN_IDS, args: [cutoffIso] }).

The single-attendee purge now calls this helper with a single-id statement; the orphan purge calls it with the orphan-id subquery. The orphan path's separate ORPHAN_DEPENDENT_TABLES list and its hand-written service_costs delete are gone — there is now one place that decides which dependent rows get cleared, used by both paths.

What stayed the same

The actual SQL behaviour is unchanged. A single-id delete was previously WHERE field = ? and is now WHERE field IN (?); for one bound value these are equivalent. The orphan subquery deletes keep the same ORPHAN_IDS subselect and the same cutoff binding, so the same rows are swept in the same order.

service_costs is now swept by the orphan purge through the same shared list instead of a separate statement — so the orphan path gains exact parity with the single-delete path rather than the near-miss it had before.

Tests

The orphan-attendee test now seeds a system_notes row for an orphan and asserts it is cleared alongside the answer and payment rows, locking in that the shared helper covers all five tables for the orphan path too.

A separate servicing edge-case test had comments referring to the now-removed ORPHAN_DEPENDENT_TABLES constant; I updated those to point at the shared mechanism so nothing references a deleted symbol.

Summary by CodeRabbit

  • Bug Fixes

    • Improved attendee cleanup to consistently remove all related records, including system notes.
    • Orphaned attendee cleanup now removes associated dependent data more reliably.
    • Added support for identifying how many orphaned attendees are eligible for cleanup.
  • Tests

    • Expanded coverage to verify that system notes and other related records are removed during orphaned attendee cleanup.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 0675b62f-115c-478e-88da-74b56192b5b3

📥 Commits

Reviewing files that changed from the base of the PR and between 32a47a0 and 0d1b098.

📒 Files selected for processing (4)
  • src/shared/db/attendees/delete.ts
  • src/shared/db/orphan-attendees.ts
  • test/integration/servicing/purge-edge-cases.test.ts
  • test/shared/db/orphan-attendees.test.ts

📝 Walkthrough

Walkthrough

The change centralizes dependent-row deletion SQL for attendee purges, reuses it for orphan-attendee cleanup, adds orphan counting, and expands tests to verify system-note removal.

Changes

Attendee purge behavior

Layer / File(s) Summary
Shared dependent-delete statement generation
src/shared/db/attendees/delete.ts
Standardizes SQL statement typing, exports attendeeDependentDeleteStatements, and uses it when purging attendee-dependent rows.
Orphan purge delegation and validation
src/shared/db/orphan-attendees.ts, test/shared/db/orphan-attendees.test.ts, test/integration/servicing/purge-edge-cases.test.ts
Delegates orphan dependent-row deletion to the shared helper, adds countOrphanedAttendees, and verifies system-note cleanup with updated test documentation.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main change: shared dependent-row purge logic across single-attendee and orphan-attendee deletion paths.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch split/attendee-purge

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

@stefan-burke
stefan-burke enabled auto-merge July 14, 2026 18:18
@stefan-burke
stefan-burke added this pull request to the merge queue Jul 14, 2026
Merged via the queue into main with commit 6e53f1c Jul 14, 2026
3 checks passed
@stefan-burke
stefan-burke deleted the split/attendee-purge branch July 14, 2026 18:25
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