2015-12-10 08:08:09 -05:00
|
|
|
class MigrateCiHipChatService < ActiveRecord::Migration
|
|
|
|
include Gitlab::Database
|
|
|
|
|
|
|
|
def up
|
|
|
|
# From properties strip `hipchat_` key
|
|
|
|
properties_query = "SELECT REPLACE(properties, '\"hipchat_', '\"') FROM ci_services " \
|
|
|
|
'JOIN ci_projects ON ci_services.project_id=ci_projects.id ' \
|
2015-12-14 05:04:47 -05:00
|
|
|
"WHERE ci_projects.gitlab_id=services.project_id AND ci_services.type='Ci::HipChatService' AND ci_services.active " \
|
|
|
|
'LIMIT 1'
|
2015-12-10 08:08:09 -05:00
|
|
|
|
|
|
|
active_query = 'SELECT 1 FROM ci_services ' \
|
|
|
|
'JOIN ci_projects ON ci_services.project_id=ci_projects.id ' \
|
2015-12-14 05:04:47 -05:00
|
|
|
"WHERE ci_projects.gitlab_id=services.project_id AND ci_services.type='Ci::HipChatService' AND ci_services.active " \
|
|
|
|
'LIMIT 1'
|
2015-12-10 08:08:09 -05:00
|
|
|
|
|
|
|
# We update the service since services are always generated for project, even if they are inactive
|
|
|
|
# Activate service and migrate properties if currently the service is not active
|
|
|
|
execute(
|
2015-12-14 05:04:47 -05:00
|
|
|
"UPDATE services SET properties=(#{properties_query}), active=#{true_value}, " \
|
|
|
|
"push_events=#{false_value}, issues_events=#{false_value}, merge_requests_events=#{false_value}, " \
|
|
|
|
"tag_push_events=#{false_value}, note_events=#{false_value}, build_events=#{true_value} " \
|
2015-12-10 08:08:09 -05:00
|
|
|
"WHERE NOT services.active AND services.type='HipchatService' AND (#{active_query}) IS NOT NULL"
|
|
|
|
)
|
|
|
|
|
|
|
|
# Tick only build_events if the service is already active
|
|
|
|
execute(
|
|
|
|
"UPDATE services SET build_events=#{true_value} " \
|
|
|
|
"WHERE services.active AND services.type='HipchatService' AND (#{active_query}) IS NOT NULL"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
end
|
|
|
|
end
|