20140505201716_migrate_agents_to_liquid_templating.rb 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. require 'liquid_migrator'
  2. class MigrateAgentsToLiquidTemplating < ActiveRecord::Migration[4.2]
  3. def up
  4. Agent.where(:type => 'Agents::HipchatAgent').each do |agent|
  5. LiquidMigrator.convert_all_agent_options(agent)
  6. end
  7. Agent.where(:type => 'Agents::EventFormattingAgent').each do |agent|
  8. agent.options['instructions'] = LiquidMigrator.convert_hash(agent.options['instructions'], {:merge_path_attributes => true, :leading_dollarsign_is_jsonpath => true})
  9. agent.save
  10. end
  11. Agent.where(:type => 'Agents::PushbulletAgent').each do |agent|
  12. LiquidMigrator.convert_all_agent_options(agent)
  13. end
  14. Agent.where(:type => 'Agents::JabberAgent').each do |agent|
  15. LiquidMigrator.convert_all_agent_options(agent)
  16. end
  17. Agent.where(:type => 'Agents::DataOutputAgent').each do |agent|
  18. LiquidMigrator.convert_all_agent_options(agent)
  19. end
  20. Agent.where(:type => 'Agents::TranslationAgent').each do |agent|
  21. agent.options['content'] = LiquidMigrator.convert_hash(agent.options['content'], {:merge_path_attributes => true, :leading_dollarsign_is_jsonpath => true})
  22. agent.save
  23. end
  24. Agent.where(:type => 'Agents::TwitterPublishAgent').each do |agent|
  25. if (message = agent.options.delete('message_path')).present?
  26. agent.options['message'] = "{{#{message}}}"
  27. agent.save
  28. end
  29. end
  30. Agent.where(:type => 'Agents::TriggerAgent').each do |agent|
  31. agent.options['message'] = LiquidMigrator.convert_make_message(agent.options['message'])
  32. agent.save
  33. end
  34. Agent.where(:type => 'Agents::PeakDetectorAgent').each do |agent|
  35. agent.options['message'] = LiquidMigrator.convert_make_message(agent.options['message'])
  36. agent.save
  37. end
  38. Agent.where(:type => 'Agents::HumanTaskAgent').each do |agent|
  39. LiquidMigrator.convert_all_agent_options(agent)
  40. end
  41. end
  42. def down
  43. raise ActiveRecord::IrreversibleMigration, "Cannot revert migration to Liquid templating"
  44. end
  45. end