Point PlanLimits plan association at SystemDefined::Plan

What does this MR do and why?

The plans table is going away, so PlanLimits now gets its plan from SystemDefined::Plan by plan_name_uid, and the uid is the only thing callers write. plan_id still gets filled from the uid until #600314 drops the column.

The docs hint for Plan.default.create_limits! doesn't work anymore, so I removed it.

Part of #571923

How to set up and validate locally

  1. In a Rails console, save limits for a plan with no plan_limits row. On GDK that's default, unless you've saved it before:

    PlanLimits.exists?(plan_name_uid: 1) # => false
    limits = Plan.default.actual_limits
    limits.update!(ci_pipeline_size: 123) # => true
    limits.plan_id == Plan.default.id # => true
    limits.plan # => #<GitlabSubscriptions::SystemDefined::Plan id: 1, name: "default", title: "Default">
    limits.destroy!
  2. Save limits for a plan with no plans row. GDK seeds every plan except early_adopter:

    Plan.find_by(name: 'early_adopter') # => nil
    limits = GitlabSubscriptions::SystemDefined::Plan.find_by(name: 'early_adopter').actual_limits
    limits.save! # => true
    limits.plan_id == Plan.find_by(name: 'early_adopter').id # => true

    On master, limits.save! raises ActiveRecord::NotNullViolation on plan_limits.plan_id.

  3. Clean up:

    limits.destroy!
    Plan.find_by(name: 'early_adopter').destroy!

Database review

Nothing saves limits for a plan without a plans row yet, so I captured the create path from a spec. GitLab.com has a plans row for every uid, so I moved the opensource one aside in the Joe clone for the INSERT plan.

PlanLimits#sync_plan_id

Admin::PlanLimitsController#create

Before: none.

After:

Raw SQL
SELECT
    "plans".*
FROM
    "plans"
WHERE
    "plans"."plan_name_uid" = 5
LIMIT 1

Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/60377/commands/165384

Admin::PlanLimits::UpdateService

Before: none.

After:

Raw SQL
SELECT
    "plans".*
FROM
    "plans"
WHERE
    "plans"."plan_name_uid" = 5
LIMIT 1

Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/60377/commands/165384

GitlabSubscriptions::SystemDefined::Plan#actual_limits

find_by

Before:

Raw SQL
SELECT
    "plans".*
FROM
    "plans"
WHERE
    "plans"."plan_name_uid" = 11
LIMIT 1

Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/60377/commands/165385

After:

Raw SQL
SELECT
    "plans".*
FROM
    "plans"
WHERE
    "plans"."plan_name_uid" = 11
LIMIT 1

Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/60377/commands/165385

uniqueness

Before: none.

After:

Raw SQL
SELECT
    1 AS one
FROM
    "plans"
WHERE
    "plans"."plan_name_uid" = 11
LIMIT 1

Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/60377/commands/165386

create

Before: none.

After:

Raw SQL
INSERT INTO "plans" ("created_at", "updated_at", "name", "title", "plan_name_uid")
    VALUES ('2026-10-01 00:00:18.953609', '2026-10-01 00:00:18.953609', 'opensource', 'Opensource', 11)
RETURNING
    "id"

Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/60377/commands/165395

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.

Edited by Ryan Cobb

Merge request reports

Loading
Loading