BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
63bd4969
Unverified
Commit
63bd4969
authored
Jan 11, 2017
by
Yorick Peterse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove more orphans when removing stray namespaces
Fixes
https://gitlab.com/gitlab-org/gitlab-ce/issues/25146
parent
4a463039
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
24 deletions
+76
-24
fix-more-orphans-remove-undeleted-groups.yml
...s/unreleased/fix-more-orphans-remove-undeleted-groups.yml
+4
-0
20161117114805_remove_undeleted_groups.rb
db/migrate/20161117114805_remove_undeleted_groups.rb
+72
-24
No files found.
changelogs/unreleased/fix-more-orphans-remove-undeleted-groups.yml
0 → 100644
View file @
63bd4969
---
title
:
Remove extra orphaned rows when removing stray namespaces
merge_request
:
7841
author
:
db/migrate/20161117114805_remove_undeleted_groups.rb
View file @
63bd4969
...
@@ -5,47 +5,87 @@ class RemoveUndeletedGroups < ActiveRecord::Migration
...
@@ -5,47 +5,87 @@ class RemoveUndeletedGroups < ActiveRecord::Migration
DOWNTIME
=
false
DOWNTIME
=
false
def
up
def
up
is_ee
=
defined?
(
Gitlab
::
License
)
if
is_ee
execute
<<-
EOF
.
strip_heredoc
DELETE FROM path_locks
WHERE project_id IN (
SELECT project_id
FROM projects
WHERE namespace_id IN (
#{
namespaces_pending_removal
}
)
);
EOF
execute
<<-
EOF
.
strip_heredoc
DELETE FROM remote_mirrors
WHERE project_id IN (
SELECT project_id
FROM projects
WHERE namespace_id IN (
#{
namespaces_pending_removal
}
)
);
EOF
end
execute
<<-
EOF
.
strip_heredoc
execute
<<-
EOF
.
strip_heredoc
DELETE FROM projects
DELETE FROM lists
WHERE namespace_id IN (
WHERE label_id IN (
SELECT id FROM (
SELECT id
SELECT id
FROM labels
FROM namespaces
WHERE group_id IN (
#{
namespaces_pending_removal
}
)
WHERE deleted_at IS NOT NULL
);
) namespace_ids
EOF
execute
<<-
EOF
.
strip_heredoc
DELETE FROM lists
WHERE board_id IN (
SELECT id
FROM boards
WHERE project_id IN (
SELECT project_id
FROM projects
WHERE namespace_id IN (
#{
namespaces_pending_removal
}
)
)
);
);
EOF
EOF
if
defined?
(
Gitlab
::
License
)
execute
<<-
EOF
.
strip_heredoc
DELETE FROM labels
WHERE group_id IN (
#{
namespaces_pending_removal
}
);
EOF
execute
<<-
EOF
.
strip_heredoc
DELETE FROM boards
WHERE project_id IN (
SELECT project_id
FROM projects
WHERE namespace_id IN (
#{
namespaces_pending_removal
}
)
)
EOF
execute
<<-
EOF
.
strip_heredoc
DELETE FROM projects
WHERE namespace_id IN (
#{
namespaces_pending_removal
}
);
EOF
if
is_ee
# EE adds these columns but we have to make sure this data is cleaned up
# EE adds these columns but we have to make sure this data is cleaned up
# here before we run the DELETE below. An alternative would be patching
# here before we run the DELETE below. An alternative would be patching
# this migration in EE but this will only result in a mess and confusing
# this migration in EE but this will only result in a mess and confusing
# migrations.
# migrations.
execute
<<-
EOF
.
strip_heredoc
execute
<<-
EOF
.
strip_heredoc
DELETE FROM protected_branch_push_access_levels
DELETE FROM protected_branch_push_access_levels
WHERE group_id IN (
WHERE group_id IN (
#{
namespaces_pending_removal
}
);
SELECT id FROM (
SELECT id
FROM namespaces
WHERE deleted_at IS NOT NULL
) namespace_ids
);
EOF
EOF
execute
<<-
EOF
.
strip_heredoc
execute
<<-
EOF
.
strip_heredoc
DELETE FROM protected_branch_merge_access_levels
DELETE FROM protected_branch_merge_access_levels
WHERE group_id IN (
WHERE group_id IN (
#{
namespaces_pending_removal
}
);
SELECT id FROM (
SELECT id
FROM namespaces
WHERE deleted_at IS NOT NULL
) namespace_ids
);
EOF
EOF
end
end
# This removes namespaces that were supposed to be
soft deleted but still
# This removes namespaces that were supposed to be
deleted but still reside
#
reside
in the database.
# in the database.
execute
"DELETE FROM namespaces WHERE deleted_at IS NOT NULL;"
execute
"DELETE FROM namespaces WHERE deleted_at IS NOT NULL;"
end
end
...
@@ -54,4 +94,12 @@ class RemoveUndeletedGroups < ActiveRecord::Migration
...
@@ -54,4 +94,12 @@ class RemoveUndeletedGroups < ActiveRecord::Migration
# If someone is trying to rollback for other reasons, we should not throw an Exception.
# If someone is trying to rollback for other reasons, we should not throw an Exception.
# raise ActiveRecord::IrreversibleMigration
# raise ActiveRecord::IrreversibleMigration
end
end
def
namespaces_pending_removal
"SELECT id FROM (
SELECT id
FROM namespaces
WHERE deleted_at IS NOT NULL
) namespace_ids"
end
end
end
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