diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-11-11 03:38:19 +0300 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-11-17 20:10:13 +0300 |
commit | 346f58249242c0ccf278175c78fc000976912771 (patch) | |
tree | 5a447a048395acf24ebd541bda0c32b815582198 /db/migrate/20161031174110_migrate_subscriptions_project_id.rb | |
parent | 9dfbe1d2a1e71ddc1f30c21a238ff8d73f271eba (diff) |
Use subqueries instead of joins to migrate subscriptions
Diffstat (limited to 'db/migrate/20161031174110_migrate_subscriptions_project_id.rb')
-rw-r--r-- | db/migrate/20161031174110_migrate_subscriptions_project_id.rb | 63 |
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 |