Update plan_limits to use uid as source of truth

What does this MR do and why?

Update plan_limits to use uid as source of truth

The source of truth should be plan name uid in preparation of moving Plan to a static list

Next steps:

  1. Update all plan limits references of plan_id to plan_name_uid.
  2. Cleanup and remove migration code.

References

#596997 (closed)

Screenshots or screen recordings

Admin UI

image

image

How to set up and validate locally

  1. Run the touched specs:
bin/rspec spec/lib/gitlab/database/migration_helpers_spec.rb \
          spec/controllers/admin/plan_limits_controller_spec.rb \
          spec/models/plan_limits_spec.rb

All green confirms: controller fallback, model set_plan_name_uid re-derivation, helper insert + update + SQL shape.

  1. Exercise the admin UI end-to-end against one plan

Go to Admin → Settings → CI/CD → Plan limits, pick Free, and before submitting:

  • Confirm the hidden field in DevTools is name="plan_limits[plan_name_uid]" with the integer uid as value (not plan_id).
  • Change ci_instance_level_variables and submit; watch the Network tab confirm the POST body sends plan_name_uid.

Then in rails console:

pl = Plan.find_by(name: 'free').actual_limits.reload
[pl.plan_name_uid, pl.plan_id, pl.ci_instance_level_variables]
# plan_name_uid == Plan::PLAN_NAME_UID_LIST[:free], plan_id unchanged, new value persisted
  1. Execute the migration helper directly

In rails console:

  m = ActiveRecord::Migration.new.extend(Gitlab::Database::MigrationHelpers)

  m.create_or_update_plan_limit('project_hooks', 'free', 42)
  m.create_or_update_plan_limit('project_hooks', 'free', 99)   # update path

  PlanLimits.joins(:plan).where(plans: { name: 'free' }).pick(:project_hooks, :plan_name_uid)
  # => [99, Plan::PLAN_NAME_UID_LIST[:free]]   # i.e. [99, 2]

  m.create_or_update_plan_limit('project_hooks', 'nonexistent', 1)
  # => ArgumentError: Unknown plan_name "nonexistent"; expected one of
  #    [:default, :free, :bronze, :silver, :premium, :gold, :ultimate,
  #     :ultimate_trial, :premium_trial, :ultimate_trial_paid_customer,
  #     :opensource, :early_adopter]

Tail log/development.log during the first call to verify the SQL matches the expected INSERT ... ON CONFLICT (plan_id) DO UPDATE SET ..., plan_name_uid = EXCLUDED.plan_name_uid shape.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #596997 (closed)

Edited by Florian Jedelhauser

Merge request reports

Loading
Loading