2018-11-13 02:27:31 -05:00
|
|
|
class RemoveRequestersThatAreOwners < ActiveRecord::Migration[4.2]
|
2016-07-05 12:55:35 -04:00
|
|
|
include Gitlab::Database::MigrationHelpers
|
|
|
|
|
|
|
|
def up
|
|
|
|
# Delete requesters that are owner of their projects and actually requested
|
|
|
|
# access to it
|
|
|
|
execute <<-SQL
|
|
|
|
DELETE FROM members
|
|
|
|
WHERE members.source_type = 'Project'
|
|
|
|
AND members.type = 'ProjectMember'
|
|
|
|
AND members.requested_at IS NOT NULL
|
|
|
|
AND members.user_id = (
|
|
|
|
SELECT namespaces.owner_id
|
|
|
|
FROM namespaces
|
|
|
|
JOIN projects ON namespaces.id = projects.namespace_id
|
|
|
|
WHERE namespaces.type IS NULL
|
|
|
|
AND projects.id = members.source_id
|
|
|
|
AND namespaces.owner_id = members.user_id);
|
|
|
|
SQL
|
|
|
|
|
|
|
|
# Delete requesters that are owner of their project's group and actually requested
|
|
|
|
# access to it
|
|
|
|
execute <<-SQL
|
|
|
|
DELETE FROM members
|
|
|
|
WHERE members.source_type = 'Project'
|
|
|
|
AND members.type = 'ProjectMember'
|
|
|
|
AND members.requested_at IS NOT NULL
|
|
|
|
AND members.user_id = (
|
|
|
|
SELECT namespaces.owner_id
|
|
|
|
FROM namespaces
|
|
|
|
JOIN projects ON namespaces.id = projects.namespace_id
|
|
|
|
WHERE namespaces.type = 'Group'
|
|
|
|
AND projects.id = members.source_id
|
|
|
|
AND namespaces.owner_id = members.user_id);
|
|
|
|
SQL
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
end
|
|
|
|
end
|