2016-11-17 11:51:17 +00:00
|
|
|
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
|
|
|
|
# for more information on how to write migrations for GitLab.
|
|
|
|
|
2018-11-13 07:27:31 +00:00
|
|
|
class RemoveUndeletedGroups < ActiveRecord::Migration[4.2]
|
2016-11-17 11:51:17 +00:00
|
|
|
DOWNTIME = false
|
|
|
|
|
|
|
|
def up
|
2017-01-11 14:59:33 +00:00
|
|
|
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
|
|
|
|
|
2016-11-22 12:12:23 +00:00
|
|
|
execute <<-EOF.strip_heredoc
|
2017-01-11 14:59:33 +00:00
|
|
|
DELETE FROM lists
|
|
|
|
WHERE label_id IN (
|
|
|
|
SELECT id
|
|
|
|
FROM labels
|
|
|
|
WHERE group_id IN (#{namespaces_pending_removal})
|
|
|
|
);
|
|
|
|
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})
|
|
|
|
)
|
2016-11-22 12:12:23 +00:00
|
|
|
);
|
|
|
|
EOF
|
|
|
|
|
2017-01-11 14:59:33 +00:00
|
|
|
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
|
2016-11-22 12:12:23 +00:00
|
|
|
# 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
|
2017-01-11 14:59:33 +00:00
|
|
|
WHERE group_id IN (#{namespaces_pending_removal});
|
2016-11-22 12:12:23 +00:00
|
|
|
EOF
|
|
|
|
|
|
|
|
execute <<-EOF.strip_heredoc
|
|
|
|
DELETE FROM protected_branch_merge_access_levels
|
2017-01-11 14:59:33 +00:00
|
|
|
WHERE group_id IN (#{namespaces_pending_removal});
|
2016-11-22 12:12:23 +00:00
|
|
|
EOF
|
|
|
|
end
|
|
|
|
|
2017-01-11 14:59:33 +00:00
|
|
|
# This removes namespaces that were supposed to be deleted but still reside
|
|
|
|
# in the database.
|
2016-11-17 11:51:17 +00:00
|
|
|
execute "DELETE FROM namespaces WHERE deleted_at IS NOT NULL;"
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
# This is an irreversible migration;
|
|
|
|
# If someone is trying to rollback for other reasons, we should not throw an Exception.
|
|
|
|
# raise ActiveRecord::IrreversibleMigration
|
|
|
|
end
|
2017-01-11 14:59:33 +00:00
|
|
|
|
|
|
|
def namespaces_pending_removal
|
|
|
|
"SELECT id FROM (
|
|
|
|
SELECT id
|
|
|
|
FROM namespaces
|
|
|
|
WHERE deleted_at IS NOT NULL
|
|
|
|
) namespace_ids"
|
|
|
|
end
|
2016-11-17 11:51:17 +00:00
|
|
|
end
|