diff options
author | Rémy Coutable <remy@rymai.me> | 2016-11-22 16:05:52 +0000 |
---|---|---|
committer | Alejandro Rodríguez <alejorro70@gmail.com> | 2016-11-22 16:07:03 +0000 |
commit | e084cbd978f22704484edb89f0663c1d56cbf338 (patch) | |
tree | 1c0b21d2197b1f6c7cb860fd74c9c13daa39a15f | |
parent | 3385c289ca80cfab216c3888f19c14ddfd1d9d03 (diff) | |
download | gitlab-ce-e084cbd978f22704484edb89f0663c1d56cbf338.tar.gz |
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
-rw-r--r-- | db/migrate/20161117114805_remove_undeleted_groups.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/db/migrate/20161117114805_remove_undeleted_groups.rb b/db/migrate/20161117114805_remove_undeleted_groups.rb index ebc2d974ae0..696914f8e4d 100644 --- a/db/migrate/20161117114805_remove_undeleted_groups.rb +++ b/db/migrate/20161117114805_remove_undeleted_groups.rb @@ -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 |