20140505201716_migrate_agents_to_liquid_templating.rb 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. class MigrateAgentsToLiquidTemplating < ActiveRecord::Migration
  2. class Agent < ActiveRecord::Base
  3. include JSONSerializedField
  4. json_serialize :options, :memory
  5. end
  6. class Agents::HipchatAgent < Agent
  7. end
  8. class Agents::EventFormattingAgent < Agent
  9. end
  10. class Agents::PushbulletAgent < Agent
  11. end
  12. class Agents::JabberAgent < Agent
  13. end
  14. class Agents::DataOutputAgent < Agent
  15. end
  16. class Agents::TranslationAgent < Agent
  17. end
  18. class Agents::TwitterPublishAgent < Agent
  19. end
  20. class Agents::TriggerAgent < Agent
  21. end
  22. class Agents::PeakDetectorAgent < Agent
  23. end
  24. class Agents::HumanTaskAgent < Agent
  25. end
  26. def up
  27. Agent.where(:type => 'Agents::HipchatAgent').each do |agent|
  28. LiquidMigrator.convert_all_agent_options(agent)
  29. end
  30. Agent.where(:type => 'Agents::EventFormattingAgent').each do |agent|
  31. agent.options['instructions'] = LiquidMigrator.convert_hash(agent.options['instructions'], {:merge_path_attributes => true, :leading_dollarsign_is_jsonpath => true})
  32. agent.save
  33. end
  34. Agent.where(:type => 'Agents::PushbulletAgent').each do |agent|
  35. LiquidMigrator.convert_all_agent_options(agent)
  36. end
  37. Agent.where(:type => 'Agents::JabberAgent').each do |agent|
  38. LiquidMigrator.convert_all_agent_options(agent)
  39. end
  40. Agent.where(:type => 'Agents::DataOutputAgent').each do |agent|
  41. LiquidMigrator.convert_all_agent_options(agent)
  42. end
  43. Agent.where(:type => 'Agents::TranslationAgent').each do |agent|
  44. agent.options['content'] = LiquidMigrator.convert_hash(agent.options['content'], {:merge_path_attributes => true, :leading_dollarsign_is_jsonpath => true})
  45. agent.save
  46. end
  47. Agent.where(:type => 'Agents::TwitterPublishAgent').each do |agent|
  48. if (message = agent.options.delete('message_path')).present?
  49. agent.options['message'] = "{{#{message}}}"
  50. agent.save
  51. end
  52. end
  53. Agent.where(:type => 'Agents::TriggerAgent').each do |agent|
  54. agent.options['message'] = LiquidMigrator.convert_make_message(agent.options['message'])
  55. agent.save
  56. end
  57. Agent.where(:type => 'Agents::PeakDetectorAgent').each do |agent|
  58. agent.options['message'] = LiquidMigrator.convert_make_message(agent.options['message'])
  59. agent.save
  60. end
  61. Agent.where(:type => 'Agents::HumanTaskAgent').each do |agent|
  62. LiquidMigrator.convert_all_agent_options(agent)
  63. end
  64. end
  65. def down
  66. raise ActiveRecord::IrreversibleMigration, "Cannot revert migration to Liquid templating"
  67. end
  68. end