20160108221620_website_agent_does_not_use_event_url.rb 1.1 KB

12345678910111213141516171819202122
  1. class WebsiteAgentDoesNotUseEventUrl < ActiveRecord::Migration[4.2]
  2. def up
  3. # Until this migration, if a WebsiteAgent received Events and did not have a `url_from_event` option set,
  4. # it would use the `url` from the Event's payload. If the Event did not have a `url` in its payload, the
  5. # WebsiteAgent would do nothing. This migration assumes that if someone has wired a WebsiteAgent to receive Events
  6. # and has not set `url_from_event` or `data_from_event`, they were trying to use the Event's `url` payload, so we
  7. # set `url_from_event` to `{{ url }}` for them.
  8. Agents::WebsiteAgent.find_each do |agent|
  9. next unless agent.sources.count > 0
  10. if !agent.options['data_from_event'].present? && !agent.options['url_from_event'].present?
  11. agent.options['url_from_event'] = '{{ url }}'
  12. agent.save!
  13. puts ">> Setting `url_from_event` on WebsiteAgent##{agent.id} to {{ url }} because it is wired"
  14. puts ">> to receive Events, and the WebsiteAgent no longer uses the Event's `url` value directly."
  15. end
  16. end
  17. end
  18. def down
  19. end
  20. end