BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
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
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
30 deletions
+15
-30
20161031174110_migrate_subscriptions_project_id.rb
...igrate/20161031174110_migrate_subscriptions_project_id.rb
+15
-30
No files found.
db/migrate/20161031174110_migrate_subscriptions_project_id.rb
View file @
346f5824
...
@@ -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
...
...
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