Unverified Commit 54bf45dc authored by Sean McGivern's avatar Sean McGivern
Browse files

Fix plan checks for mirror queries

Plans are no longer through namespace.plan_id, but through the root
namespace via gitlab_subscriptions.
parent 722c0351
Pipeline #149815 passed with stage
in 45 seconds
......@@ -8,6 +8,7 @@ module GitLab
# This class works under the assumption you do COUNT(*) queries, define
# queries in the QUERIES constant. If in doubt how these work, read
# #construct_query
# rubocop:disable Metrics/ClassLength
class RowCountCollector < Base
projects.mirror = true
......@@ -19,8 +20,15 @@ module GitLab
select: :projects,
joins: <<~SQL,
INNER JOIN project_mirror_data ON project_mirror_data.project_id = projects.id
INNER JOIN namespaces ON projects.namespace_id = namespaces.id
LEFT JOIN plans ON namespaces.plan_id = plans.id
INNER JOIN namespaces AS root_namespaces ON root_namespaces.id = (
WITH RECURSIVE "base_and_ancestors" AS (
(SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."id" = projects.namespace_id)
(SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."id" = "base_and_ancestors"."parent_id")
) SELECT "namespaces".id FROM "base_and_ancestors" AS "namespaces" WHERE "namespaces"."parent_id" IS NULL
LEFT JOIN gitlab_subscriptions ON gitlab_subscriptions.namespace_id = root_namespaces.id
LEFT JOIN plans ON plans.id = gitlab_subscriptions.hosted_plan_id
check: "SELECT 1 FROM information_schema.tables WHERE table_name='plans'"
......@@ -189,6 +197,7 @@ module GitLab
query_string << ";"
# rubocop:enable Metrics/ClassLength
# The prober which is called when gathering metrics
class RowCountProber
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment