[Plan] Create foreign key constraints for new name_uid columns

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

  • Close this issue

Objective

Create foreign key constraints between the new name_uid columns and validate data integrity across all referencing tables.

⚠️ INFO: May be this is not needed because once we make the plans table FixedItemModels there won't be any foreign key reference?

Prerequisites

  • Application code updated to use new associations (#571422)

Tasks

  • Create foreign key constraints for new columns:
    • plan_limits.plan_name_uid → plans.name_uid
    • gitlab_subscriptions.hosted_plan_name_uid → plans.name_uid
    • gitlab_subscription_histories.hosted_plan_name_uid → plans.name_uid
    • Other referencing tables as identified
  • Validate data integrity before adding constraints
  • Handle any orphaned records or data inconsistencies
  • Add not-null constraints where appropriate
  • Test constraint enforcement
  • Ensure constraints are properly indexed for performance

Data Validation Steps

  • Verify all referencing records have valid name_uid values
  • Identify and handle orphaned records
  • Check for any null values that should not exist
  • Validate enum values are within expected range

Migration Strategy

  1. Validate data integrity first
  2. Clean up any orphaned or invalid records
  3. Add foreign key constraints
  4. Add not-null constraints where appropriate
  5. Verify constraint enforcement works correctly

Acceptance Criteria

  • Foreign key constraints created for all new columns
  • Data integrity validated and maintained
  • No orphaned records remain
  • Constraints properly enforce referential integrity
  • Performance impact assessed and acceptable
  • Rollback plan tested and documented

References

  • Parent Epic: Convert `plans` table to be hard-coded in appli... (&19409)
  • Original Issue: #519892 (closed)
Edited Nov 24, 2025 by 🤖 GitLab Bot 🤖
Assignee Loading
Time tracking Loading