Read subscription plans from SystemDefined::Plan
What does this MR do and why?
Subscriptions now read their plan from SystemDefined::Plan by hosted_plan_name_uid instead of the plans table, which we're dropping (&20087). Namespace#actual_plan, the sign-in tier cookie, the group plans preloader, and the admin plan dropdown moved over too, and !261209 (merged) did the same for SubscriptionHistory. This waits on !261968 (merged), since actual_plan no longer creates the default and free rows.
I kept master's two-way sync with hosted_plan_id, since the previous release still reads it during the deploy. #600315 removes the hosted_plan_id side.
Part of #571923.
How to set up and validate locally
- Run the GDK with GitLab.com simulated (Simulate a SaaS instance).
- As an admin, edit any group under Admin > Groups. The Plan dropdown lists the 12 plans with their GitLab.com titles. Pick Ultimate and save, and the group page shows Plan: Ultimate.
GET /api/v4/groups/:id/epicsnow returns 200.- Set Plan to No plan and save. The group page shows No Plan.
PUT /api/v4/namespaces/:id/gitlab_subscriptionwithplan_code=freereturns thefreeplan, and the epics call returns 403.
Database review
GitlabSubscriptions::CurrentActivePlansForUserFinder#execute
ActiveSession.set_marketing_user_cookies
Before:
Raw SQL
WITH "members" AS MATERIALIZED (
SELECT
"members"."source_id"
FROM
"members"
WHERE
"members"."type" = 'GroupMember'
AND "members"."source_type" = 'Namespace'
AND "members"."requested_at" IS NULL
AND (
members.access_level > 5
)
AND "members"."user_id" = 1614863
)
SELECT DISTINCT
"plans"."name"
FROM
"plans"
INNER JOIN "gitlab_subscriptions" ON "gitlab_subscriptions"."hosted_plan_id" = "plans"."id"
WHERE
"plans"."name" IN ('free', 'premium', 'ultimate')
AND "gitlab_subscriptions"."namespace_id" IN (
SELECT
"source_id"
FROM
"members")
LIMIT 3Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/62255/commands/167363
After:
Raw SQL
WITH "members" AS MATERIALIZED (
SELECT
"members"."source_id"
FROM
"members"
WHERE
"members"."type" = 'GroupMember'
AND "members"."source_type" = 'Namespace'
AND "members"."requested_at" IS NULL
AND (
members.access_level > 5
)
AND "members"."user_id" = 1614863
)
SELECT DISTINCT
"gitlab_subscriptions"."hosted_plan_name_uid"
FROM
"gitlab_subscriptions"
WHERE
"gitlab_subscriptions"."hosted_plan_name_uid" IN (2, 5, 7)
AND "gitlab_subscriptions"."namespace_id" IN (
SELECT
"source_id"
FROM
"members")
LIMIT 3Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/62255/commands/167364
GitlabSubscription#plan_code=
POST /namespaces/:id/gitlab_subscription
Before:
Raw SQL
SELECT
"plans".*
FROM
"plans"
WHERE
"plans"."name" = 'premium'
LIMIT 1Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/62255/commands/167370
After:
Raw SQL
SELECT
"plans".*
FROM
"plans"
WHERE
"plans"."plan_name_uid" = 5
LIMIT 1Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/62778/commands/167944
PUT /namespaces/:id/gitlab_subscription
Before:
Raw SQL
SELECT
"plans".*
FROM
"plans"
WHERE
"plans"."name" = 'ultimate'
LIMIT 1Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/62255/commands/167371
After:
Raw SQL
SELECT
"plans".*
FROM
"plans"
WHERE
"plans"."plan_name_uid" = 7
LIMIT 1Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/62255/commands/167373
PUT /namespaces/:id
Before:
Raw SQL
SELECT
"plans".*
FROM
"plans"
WHERE
"plans"."name" = 'ultimate'
LIMIT 1Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/62255/commands/167371
After:
Raw SQL
SELECT
"plans".*
FROM
"plans"
WHERE
"plans"."plan_name_uid" = 7
LIMIT 1Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/62255/commands/167373
PUT /internal/gitlab_subscriptions/namespaces/:id
Before:
Raw SQL
SELECT
"plans".*
FROM
"plans"
WHERE
"plans"."name" = 'premium'
LIMIT 1Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/62255/commands/167370
After:
Raw SQL
SELECT
"plans".*
FROM
"plans"
WHERE
"plans"."plan_name_uid" = 5
LIMIT 1Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/62778/commands/167944
POST /internal/gitlab_subscriptions/namespaces/:id/provision
Before:
Raw SQL
SELECT
"plans".*
FROM
"plans"
WHERE
"plans"."name" = 'premium'
LIMIT 1Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/62255/commands/167370
After:
Raw SQL
SELECT
"plans".*
FROM
"plans"
WHERE
"plans"."plan_name_uid" = 5
LIMIT 1Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/62778/commands/167944
POST /internal/gitlab_subscriptions/namespaces/:id/gitlab_subscription
Before:
Raw SQL
SELECT
"plans".*
FROM
"plans"
WHERE
"plans"."name" = 'premium'
LIMIT 1Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/62255/commands/167370
After:
Raw SQL
SELECT
"plans".*
FROM
"plans"
WHERE
"plans"."plan_name_uid" = 5
LIMIT 1Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/62778/commands/167944
PUT /internal/gitlab_subscriptions/namespaces/:id/gitlab_subscription
Before:
Raw SQL
SELECT
"plans".*
FROM
"plans"
WHERE
"plans"."name" = 'ultimate'
LIMIT 1Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/62255/commands/167371
After:
Raw SQL
SELECT
"plans".*
FROM
"plans"
WHERE
"plans"."plan_name_uid" = 7
LIMIT 1Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/62255/commands/167373
Namespace#generate_subscription
Before:
Raw SQL
SELECT
"plans".*
FROM
"plans"
WHERE
"plans"."name" = 'free'
LIMIT 1Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/62255/commands/167372
After:
Raw SQL
SELECT
"plans".*
FROM
"plans"
WHERE
"plans"."plan_name_uid" = 2
LIMIT 1Plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/62778/commands/167945
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.