diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2016-11-22 13:12:23 +0100 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2016-11-22 14:56:13 +0100 |
commit | 5586ff5784a917840c7069e70a521e13e66749c1 (patch) | |
tree | 6cdce9728bef44eb238194bef760cc1704e80bde /db | |
parent | d6603493ea6ef347a5193c6df186c4576ca887b2 (diff) | |
download | gitlab-ce-5586ff5784a917840c7069e70a521e13e66749c1.tar.gz |
Handle orphans when removing soft deleted groupsfix-remove-undeleted-groups-orphans
There may be more tables but these were the tables that were problematic
for GitLab.com due to foreign key constraints (without cascading
deletes).
Diffstat (limited to 'db')
-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 |