20241027081918_website_agent_rename_array_to_single_array.rb 814 B

1234567891011121314151617181920212223242526272829
  1. class WebsiteAgentRenameArrayToSingleArray < ActiveRecord::Migration[6.1]
  2. def up
  3. Agents::WebsiteAgent.find_each do |agent|
  4. case extract = agent.options['extract']
  5. when Hash
  6. extract.each_value do |details|
  7. if details.is_a?(Hash) && details.key?('array')
  8. details['single_array'] = details.delete('array')
  9. end
  10. end
  11. agent.save(validate: false)
  12. end
  13. end
  14. end
  15. def down
  16. Agents::WebsiteAgent.find_each do |agent|
  17. case extract = agent.options['extract']
  18. when Hash
  19. extract.each_value do |details|
  20. if details.is_a?(Hash) && details.key?('single_array')
  21. details['array'] = details.delete('single_array')
  22. end
  23. end
  24. agent.save(validate: false)
  25. end
  26. end
  27. end
  28. end