Skip to content
Snippets Groups Projects
Commit 26ec4b97 authored by Rémy Coutable's avatar Rémy Coutable
Browse files

Merge branch 'fix-remove-undeleted-groups-orphans' into 'master'

Handle orphans when removing soft deleted groups

This fixes the migration from https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/7528 so it handles orphans as mentioned in https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/7528/diffs#note_18800962.

This needs to go in 8.14.0 as otherwise customers may run into the same problem.

See merge request !7657
parents 12e4f5bd 5586ff57
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -5,6 +5,47 @@ class RemoveUndeletedGroups < ActiveRecord::Migration
DOWNTIME = false
 
def up
execute <<-EOF.strip_heredoc
DELETE FROM projects
WHERE namespace_id IN (
SELECT id FROM (
SELECT id
FROM namespaces
WHERE deleted_at IS NOT NULL
) namespace_ids
);
EOF
if defined?(Gitlab::License)
# 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
# this migration in EE but this will only result in a mess and confusing
# migrations.
execute <<-EOF.strip_heredoc
DELETE FROM protected_branch_push_access_levels
WHERE group_id IN (
SELECT id FROM (
SELECT id
FROM namespaces
WHERE deleted_at IS NOT NULL
) namespace_ids
);
EOF
execute <<-EOF.strip_heredoc
DELETE FROM protected_branch_merge_access_levels
WHERE group_id IN (
SELECT id FROM (
SELECT id
FROM namespaces
WHERE deleted_at IS NOT NULL
) namespace_ids
);
EOF
end
# This removes namespaces that were supposed to be soft deleted but still
# reside in the database.
execute "DELETE FROM namespaces WHERE deleted_at IS NOT NULL;"
end
 
Loading
Loading
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