2016-06-09 08:39:16 -04:00
|
|
|
# rubocop:disable all
|
2018-11-13 02:27:31 -05:00
|
|
|
class MoveSlackServiceToWebhook < ActiveRecord::Migration[4.2]
|
2016-12-06 12:59:03 -05:00
|
|
|
|
|
|
|
DOWNTIME = true
|
|
|
|
DOWNTIME_REASON = 'Move old fields "token" and "subdomain" to one single field "webhook"'
|
|
|
|
|
2014-10-06 10:50:24 -04:00
|
|
|
def change
|
2016-12-20 16:14:33 -05:00
|
|
|
SlackService.all.each do |slack_service|
|
2014-10-06 10:50:24 -04:00
|
|
|
if ["token", "subdomain"].all? { |property| slack_service.properties.key? property }
|
|
|
|
token = slack_service.properties['token']
|
|
|
|
subdomain = slack_service.properties['subdomain']
|
|
|
|
webhook = "https://#{subdomain}.slack.com/services/hooks/incoming-webhook?token=#{token}"
|
|
|
|
slack_service.properties['webhook'] = webhook
|
|
|
|
slack_service.properties.delete('token')
|
|
|
|
slack_service.properties.delete('subdomain')
|
|
|
|
# Room is configured on the Slack side
|
|
|
|
slack_service.properties.delete('room')
|
2015-02-25 12:22:08 -05:00
|
|
|
slack_service.save(validate: false)
|
2014-10-06 10:50:24 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|