summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-11-10 22:38:19 -0200
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-11-15 16:09:47 -0200
commit74656ad3b6c35fe6ecb37fa1d45d94962dc8677d (patch)
tree9d9b504c7e6a7ae43972bced9bbc8300062a5683
parent4c63e9a997b42747651f09d2905a10b7154ea96b (diff)
downloadgitlab-ce-74656ad3b6c35fe6ecb37fa1d45d94962dc8677d.tar.gz
Use subqueries instead of joins to migrate subscriptions
-rw-r--r--db/migrate/20161031174110_migrate_subscriptions_project_id.rb63
1 files changed, 24 insertions, 39 deletions
diff --git a/db/migrate/20161031174110_migrate_subscriptions_project_id.rb b/db/migrate/20161031174110_migrate_subscriptions_project_id.rb
index b890a294431..9e1bdb7c567 100644
--- a/db/migrate/20161031174110_migrate_subscriptions_project_id.rb
+++ b/db/migrate/20161031174110_migrate_subscriptions_project_id.rb
@@ -5,50 +5,35 @@ class MigrateSubscriptionsProjectId < ActiveRecord::Migration
DOWNTIME_REASON = 'Subscriptions will not work as expected until this migration is complete.'
def up
- if Gitlab::Database.mysql?
- execute <<-EOF.strip_heredoc
- UPDATE subscriptions
- INNER JOIN issues ON issues.id = subscriptions.subscribable_id AND subscriptions.subscribable_type = 'Issue'
- SET subscriptions.project_id = 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
+ execute <<-EOF.strip_heredoc
+ UPDATE subscriptions
+ SET project_id = (
+ SELECT issues.project_id
FROM issues
- WHERE issues.id = subscriptions.subscribable_id
- AND subscriptions.subscribable_type = 'Issue';
- EOF
+ WHERE issues.id = subscriptions.subscribable_id AND subscriptions.subscribable_type = 'Issue'
+ )
+ WHERE subscriptions.subscribable_type = 'Issue';
+ EOF
- execute <<-EOF.strip_heredoc
- UPDATE subscriptions
- SET project_id = merge_requests.target_project_id
+ execute <<-EOF.strip_heredoc
+ UPDATE subscriptions
+ SET project_id = (
+ SELECT merge_requests.target_project_id
FROM merge_requests
- WHERE merge_requests.id = subscriptions.subscribable_id
- AND subscriptions.subscribable_type = 'MergeRequest';
- EOF
+ WHERE merge_requests.id = subscriptions.subscribable_id AND subscriptions.subscribable_type = 'MergeRequest'
+ )
+ WHERE subscriptions.subscribable_type = 'MergeRequest';
+ EOF
- execute <<-EOF.strip_heredoc
- UPDATE subscriptions
- SET project_id = projects.id
+ execute <<-EOF.strip_heredoc
+ UPDATE subscriptions
+ SET project_id = (
+ SELECT projects.id
FROM labels INNER JOIN projects ON projects.id = labels.project_id
- WHERE labels.id = subscriptions.subscribable_id
- AND subscriptions.subscribable_type = 'Label';
- EOF
- end
+ WHERE labels.id = subscriptions.subscribable_id AND subscriptions.subscribable_type = 'Label'
+ )
+ WHERE subscriptions.subscribable_type = 'Label';
+ EOF
end
def down