diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-10-31 16:15:22 -0200 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-11-17 15:10:12 -0200 |
commit | 731946bad2df5b2b369db53d965061d71bf6be77 (patch) | |
tree | 326e5bd110e64541a9e46d7a7f27dd9e14bd097f /db/migrate | |
parent | 4fcae04f7bb4823d740a18419f21b8d154b4ef89 (diff) | |
download | gitlab-ce-731946bad2df5b2b369db53d965061d71bf6be77.tar.gz |
Migrate subscribable project id to the subscriptions table
Diffstat (limited to 'db/migrate')
-rw-r--r-- | db/migrate/20161031174110_migrate_subscriptions_project_id.rb | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/db/migrate/20161031174110_migrate_subscriptions_project_id.rb b/db/migrate/20161031174110_migrate_subscriptions_project_id.rb new file mode 100644 index 00000000000..b890a294431 --- /dev/null +++ b/db/migrate/20161031174110_migrate_subscriptions_project_id.rb @@ -0,0 +1,59 @@ +class MigrateSubscriptionsProjectId < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = true + 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 + FROM issues + WHERE issues.id = subscriptions.subscribable_id + AND subscriptions.subscribable_type = 'Issue'; + EOF + + execute <<-EOF.strip_heredoc + UPDATE subscriptions + SET project_id = merge_requests.target_project_id + FROM merge_requests + WHERE merge_requests.id = subscriptions.subscribable_id + AND subscriptions.subscribable_type = 'MergeRequest'; + EOF + + execute <<-EOF.strip_heredoc + UPDATE subscriptions + SET project_id = 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 + end + + def down + execute <<-EOF.strip_heredoc + UPDATE subscriptions SET project_id = NULL; + EOF + end +end |