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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
731946ba
Commit
731946ba
authored
Oct 31, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate subscribable project id to the subscriptions table
parent
4fcae04f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
0 deletions
+59
-0
db/migrate/20161031174110_migrate_subscriptions_project_id.rb
...igrate/20161031174110_migrate_subscriptions_project_id.rb
+59
-0
No files found.
db/migrate/20161031174110_migrate_subscriptions_project_id.rb
0 → 100644
View file @
731946ba
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
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