2018-11-13 02:27:31 -05:00
|
|
|
class MigrateSubscriptionsProjectId < ActiveRecord::Migration[4.2]
|
2016-10-31 14:15:22 -04:00
|
|
|
include Gitlab::Database::MigrationHelpers
|
|
|
|
|
|
|
|
DOWNTIME = true
|
|
|
|
DOWNTIME_REASON = 'Subscriptions will not work as expected until this migration is complete.'
|
|
|
|
|
|
|
|
def up
|
2016-11-10 19:38:19 -05:00
|
|
|
execute <<-EOF.strip_heredoc
|
|
|
|
UPDATE subscriptions
|
|
|
|
SET project_id = (
|
|
|
|
SELECT issues.project_id
|
2016-10-31 14:15:22 -04:00
|
|
|
FROM issues
|
2016-11-17 10:50:14 -05:00
|
|
|
WHERE issues.id = subscriptions.subscribable_id
|
2016-11-10 19:38:19 -05:00
|
|
|
)
|
|
|
|
WHERE subscriptions.subscribable_type = 'Issue';
|
|
|
|
EOF
|
2016-10-31 14:15:22 -04:00
|
|
|
|
2016-11-10 19:38:19 -05:00
|
|
|
execute <<-EOF.strip_heredoc
|
|
|
|
UPDATE subscriptions
|
|
|
|
SET project_id = (
|
|
|
|
SELECT merge_requests.target_project_id
|
2016-10-31 14:15:22 -04:00
|
|
|
FROM merge_requests
|
2016-11-17 10:50:14 -05:00
|
|
|
WHERE merge_requests.id = subscriptions.subscribable_id
|
2016-11-10 19:38:19 -05:00
|
|
|
)
|
|
|
|
WHERE subscriptions.subscribable_type = 'MergeRequest';
|
|
|
|
EOF
|
2016-10-31 14:15:22 -04:00
|
|
|
|
2016-11-10 19:38:19 -05:00
|
|
|
execute <<-EOF.strip_heredoc
|
|
|
|
UPDATE subscriptions
|
|
|
|
SET project_id = (
|
|
|
|
SELECT projects.id
|
2016-10-31 14:15:22 -04:00
|
|
|
FROM labels INNER JOIN projects ON projects.id = labels.project_id
|
2016-11-17 10:50:14 -05:00
|
|
|
WHERE labels.id = subscriptions.subscribable_id
|
2016-11-10 19:38:19 -05:00
|
|
|
)
|
|
|
|
WHERE subscriptions.subscribable_type = 'Label';
|
|
|
|
EOF
|
2016-10-31 14:15:22 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
execute <<-EOF.strip_heredoc
|
|
|
|
UPDATE subscriptions SET project_id = NULL;
|
|
|
|
EOF
|
|
|
|
end
|
|
|
|
end
|