Skip to content
Snippets Groups Projects
Commit c08a9239 authored by alex pooley's avatar alex pooley
Browse files

Backfill traversal_ids for gitlab-org staging

This migration only applies to staging.
parent 25903c13
No related branches found
No related tags found
No related merge requests found
---
title: Backfill traversal_ids for gitlab-org staging
merge_request: 56293
author:
type: performance
# frozen_string_literal: true
class SetTraversalIdsForGitlabOrgGroupStaging < ActiveRecord::Migration[6.0]
DOWNTIME = false
def up
return unless Gitlab.staging?
# namespace ID 9970 is gitlab-org on staging.
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
# We can't reverse this data migration.
# This method intentionally left blank.
# def down
# end
end
01bbe2af2bc6bdaa6bf1e2fe10557e3f9f969cc60a348f188fbfe126ea7ea97d
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment