Backfill UserAddOnAssignmentVersion table with historical data from UserAddOnAssignment

Summary

Create a data migration to backfill the UserAddOnAssignmentVersion table with historical data from the UserAddOnAssignment table for assignments created before 2024-11-07. This is needed to ensure AI metrics and analytics have complete historical data.

Background

The UserAddOnAssignmentVersion model with papertrail tracking was introduced on 2024-11-07 via !169180 (merged). However, this means that add-on assignments created before this date don't have corresponding version records, which affects:

  1. AI Impact Analytics that rely on historical assignment data
  2. ClickHouse synchronization for historical metrics
  3. Accurate reporting of add-on usage over time

As discussed in #498633 (comment 2595465956), we need to backfill the _versions table for assignments that don't have any version records.

Proposal

  1. Create a data migration that:

    • Identifies UserAddOnAssignment records without corresponding UserAddOnAssignmentVersion entries
    • Creates UserAddOnAssignmentVersion records with:
      • event = 'created'
      • Proper created_at timestamp from the original assignment
      • All necessary fields to maintain data integrity
  2. Ensure proper synchronization:

    • Verify that the backfilled records are properly synced to ClickHouse
    • Update sync cursors if necessary to ensure complete data transfer
  3. Data validation:

    • Compare ClickHouse data with PostgreSQL data for add-on assignments under gitlab-org
    • Ensure data accuracy and completeness after backfill
  4. Documentation:

    • Document the backfill process and any limitations
    • Update AI Impact Analytics documentation if needed

Acceptance Criteria

  • Data migration successfully creates UserAddOnAssignmentVersion records for all UserAddOnAssignment records created before 2024-11-07
  • Backfilled records have correct created_at timestamps and event='created'
  • All backfilled data is properly synchronized to ClickHouse
  • AI metrics show consistent historical data after backfill
  • Data validation confirms accuracy between PG and ClickHouse
  • Documentation is updated to reflect the backfill process

Technical Notes

Related Issues

  • Parent issue: #498633 (closed)
  • Related to ClickHouse sync issues and AI metrics accuracy