Backfill missing papertrail versions for orphaned addon assignments
Summary
We need to create a backfill migration to generate missing papertrail versions for orphaned addon assignments that don't have corresponding subscription_user_add_on_assignment_versions records. This is a follow-up to the previous backfill work done in !196272 (merged).
Problem
As discovered in #498633 (comment 2644308842), we currently have ~9000 orphan addon assignment records without papertrail versions. Even after the initial backfill migration, new orphan records continue to be created because:
-
GitlabSubscriptions::Duo::BulkAssignServiceusesupsert_allwhich bypasses ActiveRecord callbacks - Other services may also bypass callbacks when creating addon assignments
- This leads to missing historical data in ClickHouse for addon assignments
Current State
Recent queries show the problem is ongoing:
- 3 weeks ago: 17,009 missing assignments (query)
- After migration: 27 missing assignments (query)
- Current: 67 missing assignments (query)
The increasing number indicates new orphan records are being created continuously.
Proposal
Create a data migration similar to !196272 (merged) that:
- Identifies addon assignments without corresponding papertrail versions
- Creates missing
subscription_user_add_on_assignment_versionsrecords - Ensures proper
event='create'and correct timestamps - Syncs the new version records to ClickHouse
Question: Can we requeue QueueBackfillSubscriptionUserAddOnAssignmentVersions ?
### Query for Investigation
Use this query to identify orphaned records:
```sql
SELECT a.id, a.created_at, a.updated_at, a.user_id, a.add_on_id
FROM subscription_user_add_on_assignments a
LEFT JOIN subscription_user_add_on_assignment_versions v ON a.id = v.item_id
WHERE v.id IS NULL
ORDER BY a.created_at DESC;
Related Issues
- Parent issue: #498633 (closed)
- Root cause fix: #566532 (closed)
- Previous backfill: !196272 (merged)