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.
Remove Foreign Key Constraints and Add Orphan Cleanup Tracking
Overview
This migration removes foreign key constraints from aggregation tables and introduces a tracking mechanism for orphan cleanup operations.
Changes
Foreign Key Removal
memberSegmentsAgg: Removed foreign key constraintmemberSegmentsAgg_memberId_fkeyorganizationSegmentsAgg: Removed foreign key constraintorganizationSegmentsAgg_organizationId_fkeyRationale: Removing these constraints allows for more flexible data management and prevents cascade deletion issues while maintaining data integrity through application-level controls.
New Table:
orphanCleanupRunsIntroduces a new tracking table to monitor and audit orphan record cleanup operations.
Fields:
id(UUID): Primary keytableName(VARCHAR): Target table namestartedAt/completedAt(TIMESTAMPTZ): Execution timestampsstatus(VARCHAR): Operation status ('running', 'completed', 'failed')orphansFound/orphansDeleted(INTEGER): Cleanup metricsexecutionTimeMs(INTEGER): Performance trackingerrorMessage(TEXT): Error details if failedNote
Medium Risk
Schema changes remove referential integrity enforcement on aggregate tables and introduce a new tracking table; risk is primarily around allowing orphaned aggregate rows and requiring application/job logic to handle cleanup correctly.
Overview
Database migration drops the foreign key constraints on
memberSegmentsAgg.memberIdandorganizationSegmentsAgg.organizationId, decoupling these aggregate tables from their parent records.It also adds a new
orphanCleanupRunstable to record/audit orphan cleanup jobs (status, timing, counts, and error message).Written by Cursor Bugbot for commit 668c2a6. This will update automatically on new commits. Configure here.