Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
3fcaac1b
Commit
3fcaac1b
authored
Mar 11, 2021
by
Alex Pooley
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backfill traversal_ids for gitlab-org staging
This migration only applies to staging.
parent
915b42b7
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
94 additions
and
0 deletions
+94
-0
changelogs/unreleased/233431-set-traversal_ids-for-gitlab-org-group.yml
...eleased/233431-set-traversal_ids-for-gitlab-org-group.yml
+5
-0
db/post_migrate/20210311045138_set_traversal_ids_for_gitlab_org_group_staging.rb
...1045138_set_traversal_ids_for_gitlab_org_group_staging.rb
+88
-0
db/schema_migrations/20210311045138
db/schema_migrations/20210311045138
+1
-0
No files found.
changelogs/unreleased/233431-set-traversal_ids-for-gitlab-org-group.yml
0 → 100644
View file @
3fcaac1b
---
title
:
Backfill traversal_ids for gitlab-org staging
merge_request
:
56293
author
:
type
:
performance
db/post_migrate/20210311045138_set_traversal_ids_for_gitlab_org_group_staging.rb
0 → 100644
View file @
3fcaac1b
# frozen_string_literal: true
class
SetTraversalIdsForGitlabOrgGroupStaging
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
def
up
return
unless
Gitlab
.
staging?
# namespace ID 9970 is gitlab-org on staging.
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
.
staging?
# namespace ID 9970 is gitlab-org on staging.
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
db/schema_migrations/20210311045138
0 → 100644
View file @
3fcaac1b
01bbe2af2bc6bdaa6bf1e2fe10557e3f9f969cc60a348f188fbfe126ea7ea97d
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment