Use subqueries instead of joins to migrate subscriptions

parent 9dfbe1d2
...@@ -5,51 +5,36 @@ class MigrateSubscriptionsProjectId < ActiveRecord::Migration ...@@ -5,51 +5,36 @@ class MigrateSubscriptionsProjectId < ActiveRecord::Migration
DOWNTIME_REASON = 'Subscriptions will not work as expected until this migration is complete.' DOWNTIME_REASON = 'Subscriptions will not work as expected until this migration is complete.'
def up def up
if Gitlab::Database.mysql?
execute <<-EOF.strip_heredoc execute <<-EOF.strip_heredoc
UPDATE subscriptions UPDATE subscriptions
INNER JOIN issues ON issues.id = subscriptions.subscribable_id AND subscriptions.subscribable_type = 'Issue' SET project_id = (
SET subscriptions.project_id = issues.project_id; SELECT issues.project_id
EOF
execute <<-EOF.strip_heredoc
UPDATE subscriptions
INNER JOIN merge_requests ON merge_requests.id = subscriptions.subscribable_id AND subscriptions.subscribable_type = 'MergeRequest'
SET subscriptions.project_id = merge_requests.target_project_id;
EOF
execute <<-EOF.strip_heredoc
UPDATE subscriptions
INNER JOIN labels ON labels.id = subscriptions.subscribable_id AND subscriptions.subscribable_type = 'Label'
INNER JOIN projects ON projects.id = labels.project_id
SET subscriptions.project_id = projects.id;
EOF
else
execute <<-EOF.strip_heredoc
UPDATE subscriptions
SET project_id = issues.project_id
FROM issues FROM issues
WHERE issues.id = subscriptions.subscribable_id WHERE issues.id = subscriptions.subscribable_id AND subscriptions.subscribable_type = 'Issue'
AND subscriptions.subscribable_type = 'Issue'; )
WHERE subscriptions.subscribable_type = 'Issue';
EOF EOF
execute <<-EOF.strip_heredoc execute <<-EOF.strip_heredoc
UPDATE subscriptions UPDATE subscriptions
SET project_id = merge_requests.target_project_id SET project_id = (
SELECT merge_requests.target_project_id
FROM merge_requests FROM merge_requests
WHERE merge_requests.id = subscriptions.subscribable_id WHERE merge_requests.id = subscriptions.subscribable_id AND subscriptions.subscribable_type = 'MergeRequest'
AND subscriptions.subscribable_type = 'MergeRequest'; )
WHERE subscriptions.subscribable_type = 'MergeRequest';
EOF EOF
execute <<-EOF.strip_heredoc execute <<-EOF.strip_heredoc
UPDATE subscriptions UPDATE subscriptions
SET project_id = projects.id SET project_id = (
SELECT projects.id
FROM labels INNER JOIN projects ON projects.id = labels.project_id FROM labels INNER JOIN projects ON projects.id = labels.project_id
WHERE labels.id = subscriptions.subscribable_id WHERE labels.id = subscriptions.subscribable_id AND subscriptions.subscribable_type = 'Label'
AND subscriptions.subscribable_type = 'Label'; )
WHERE subscriptions.subscribable_type = 'Label';
EOF EOF
end end
end
def down def down
execute <<-EOF.strip_heredoc execute <<-EOF.strip_heredoc
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment