Commit 8d8fc7dd authored by Yannis Roussos's avatar Yannis Roussos

Merge branch '325509-set-namespaces-traversal_ids-for-production-gitlab-org-group' into 'master'

Resolve "Set namespaces.traversal_ids for production gitlab-org group"

See merge request gitlab-org/gitlab!57075
parents a3687a6d 6d75e4e1
---
title: Backfill traversal_ids for gitlab-org .com
merge_request: 57075
author:
type: performance
# frozen_string_literal: true
class SetTraversalIdsForGitlabOrgGroupCom < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def up
return unless Gitlab.com?
# namespace ID 9970 is gitlab-org on .com
with_lock_retries do
execute(<<~SQL)
UPDATE
namespaces
SET
traversal_ids = cte.traversal_ids
FROM
(
WITH RECURSIVE cte(id, traversal_ids, cycle) AS (
VALUES
(9970, ARRAY[9970], false)
UNION ALL
SELECT
n.id,
cte.traversal_ids || n.id,
n.id = ANY(cte.traversal_ids)
FROM
namespaces n,
cte
WHERE
n.parent_id = cte.id
AND NOT cycle
)
SELECT
id,
traversal_ids
FROM
cte FOR
UPDATE
) as cte
WHERE
namespaces.id = cte.id
AND namespaces.traversal_ids <> cte.traversal_ids
SQL
end
end
def down
return unless Gitlab.com?
# namespace ID 9970 is gitlab-org on .com
with_lock_retries do
execute(<<~SQL)
UPDATE
namespaces
SET
traversal_ids = '{}'
FROM
(
WITH RECURSIVE cte(id, traversal_ids, cycle) AS (
VALUES
(9970, ARRAY[9970], false)
UNION ALL
SELECT
n.id,
cte.traversal_ids || n.id,
n.id = ANY(cte.traversal_ids)
FROM
namespaces n,
cte
WHERE
n.parent_id = cte.id
AND NOT cycle
)
SELECT
id,
traversal_ids
FROM
cte FOR
UPDATE
) as cte
WHERE
namespaces.id = cte.id
SQL
end
end
end
2387c8a5516aaf8bcf44c9bad45bfc9844d68d2c03330f67773ce046b21a7a6c
\ No newline at end of file
Markdown is supported
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