[Plan] Update Plan model and associations to use name_uid enum
Objective
Enable the transition from plan_id to plan_name_uid associations by automatically populating the new *_plan_name_uid columns whenever records are created or updated.
What was implemented
!218355 - Write plan_name_uid columns on create/update implemented automatic syncing of *_plan_name_uid columns during create and update operations for:
| Model | Column |
|---|---|
PlanLimits |
plan_name_uid |
GitlabSubscription |
hosted_plan_name_uid |
Ci::Runner |
allowed_plan_name_uids |
Ci::PendingBuild |
plan_name_uid |
When a plan_id is set or changed, the corresponding *_plan_name_uid column is automatically populated with the associated plan's name_uid.
Prerequisites
- New columns added to referencing tables (#571420 (closed))
Migration plan
- Part 1: Write to new columns (!218355 (merged) - merged)
- Part 2: Backfill existing data (#571448)
- Part 3: Switch reads to use new columns
References
- Parent Epic: &19409
- Original Issue: #519892 (closed)
- Previous: #571420 (closed)
- Next: #571448
Original issue description
Objective
Update the Plan model and its associations to use the new name_uid enum while maintaining backward compatibility during the transition period.
Prerequisites
- New columns added to referencing tables (#571420 (closed))
Tasks
-
Update associations in Plan model:
has_many :plan_limits, foreign_key: :plan_name_uid, primary_key: :name_uidhas_many :gitlab_subscriptions, foreign_key: :hosted_plan_name_uid, primary_key: :name_uid
-
Update inverse associations in referencing models, mark it as
optional:-
PlanLimits:belongs_to :plan, foreign_key: :plan_name_uid, primary_key: :name_uid -
GitlabSubscription:belongs_to :hosted_plan, foreign_key: :hosted_plan_name_uid, primary_key: :name_uid
-
- Add backward compatibility methods if needed
-
pane_name_uidshould be always set duringinsertorupdate - Update Plan factory for tests
- Ensure JiHu-specific code is updated appropriately
Backward Compatibility Strategy
- Keep old associations for backward compatibility during transition phase
- Provide fallback methods that work with both old and new columns
- Gradual transition approach to avoid breaking changes
Testing Requirements
- Update existing tests to use new associations
- Add tests for backward compatibility
- Test both old and new association paths
- Validate enum functionality works correctly
Acceptance Criteria
- Backward compatibility maintained during transition
- All tests pass
- JiHu-specific code updated appropriately
- No breaking changes for existing functionality
References
- Parent Epic: Convert `plans` table to be hard-coded in appli... (&19409)
- Original Issue: #519892 (closed)
- Previous: #571420 (closed)
Edited by Ryan Cobb