Resolve admin plan limits API plans through SystemDefined::Plan

What does this MR do and why?

Switches the admin plan limits API from Admin::PlansFinder to GitlabSubscriptions::SystemDefined::Plan, so it reads limits by plan_name_uid.

Closes #596997 (closed)

How to set up and validate locally

  1. Create a personal access token for an admin user with the api and admin_mode scopes.

  2. Change a limit on a paid plan:

    curl --request PUT --header "PRIVATE-TOKEN: <token>" \
      "http://gdk.test:3000/api/v4/application/plan_limits?plan_name=premium&maven_max_file_size=100"

    It returns 200 with "maven_max_file_size": 100.

  3. In a Rails console, check that the row is keyed by uid and still has plan_id:

    limits = PlanLimits.find_by(plan_name_uid: 5) # premium
    limits.maven_max_file_size # => 100
    limits.plan_id == Plan.find_by(name: 'premium').id # => true
  4. Request a plan that has no plans row. free has none unless your GDK has run as GitLab.com, so check first that Plan.exists?(name: 'free') is false:

    curl --header "PRIVATE-TOKEN: <token>" "http://gdk.test:3000/api/v4/application/plan_limits?plan_name=free"

    It returns 404 Plan Not Found, the same as on master.

Database review

I shortened the column lists to "<table>".*.

GET /api/v4/application/plan_limits

current_plan

Before:

SELECT
    "plans".*
FROM
    "plans"
WHERE
    "plans"."name" = 'default'
LIMIT 1

Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/58555/commands/163548

After:

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

Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/58555/commands/163549

actual_limits

Before:

SELECT
    "plan_limits".*
FROM
    "plan_limits"
WHERE
    "plan_limits"."plan_id" = <plan id>
LIMIT 1

Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/58555/commands/163550

After:

SELECT
    "plan_limits".*
FROM
    "plan_limits"
WHERE
    "plan_limits"."plan_name_uid" = 1
LIMIT 1

Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/58555/commands/163551

PUT /api/v4/application/plan_limits

current_plan

Before:

SELECT
    "plans".*
FROM
    "plans"
WHERE
    "plans"."name" = 'default'
LIMIT 1

Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/58555/commands/163548

After:

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

Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/58555/commands/163549

actual_limits

Before:

SELECT
    "plan_limits".*
FROM
    "plan_limits"
WHERE
    "plan_limits"."plan_id" = <plan id>
LIMIT 1

Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/58555/commands/163550

After:

SELECT
    "plan_limits".*
FROM
    "plan_limits"
WHERE
    "plan_limits"."plan_name_uid" = 1
LIMIT 1

Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/58555/commands/163551

PlanLimits#set_plan_name_uid (plan has no plan_limits row yet)

Before: none.

After:

SELECT
    "plans".*
FROM
    "plans"
WHERE
    "plans"."plan_name_uid" = 1
LIMIT 1

Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/58555/commands/163552

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