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:

  1. GitlabSubscriptions::Duo::BulkAssignService uses upsert_all which bypasses ActiveRecord callbacks
  2. Other services may also bypass callbacks when creating addon assignments
  3. 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:

  1. Identifies addon assignments without corresponding papertrail versions
  2. Creates missing subscription_user_add_on_assignment_versions records
  3. Ensures proper event='create' and correct timestamps
  4. 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

Edited by Amr Taha