Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
346f5824
Commit
346f5824
authored
Nov 10, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use subqueries instead of joins to migrate subscriptions
parent
9dfbe1d2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
39 deletions
+24
-39
db/migrate/20161031174110_migrate_subscriptions_project_id.rb
...igrate/20161031174110_migrate_subscriptions_project_id.rb
+24
-39
No files found.
db/migrate/20161031174110_migrate_subscriptions_project_id.rb
View file @
346f5824
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment