diff --git a/db/migrate/20241011071014_update_item_name_to_product_in_od_report.rb b/db/migrate/20241011071014_update_item_name_to_product_in_od_report.rb new file mode 100644 index 0000000000..9cd5b6dbf5 --- /dev/null +++ b/db/migrate/20241011071014_update_item_name_to_product_in_od_report.rb @@ -0,0 +1,39 @@ +class UpdateItemNameToProductInODReport < ActiveRecord::Migration[7.0] + # OD: Orders and Distributors + def up + # adding subtype filter just to be safe + options = ReportRenderingOptions.where(report_type: 'orders_and_distributors', report_subtype: nil) + + options.find_each do |option| + begin + fields_to_show = option.options[:fields_to_show] + next if fields_to_show&.exclude?('item_name') + + fields_to_show.delete('item_name') + fields_to_show << 'product' + option.update(options: option.options) + rescue StandardError => e + puts "Failed to update rendering option with id: #{option.id}" + puts "Error: #{e.message}" + end + end + end + + def down + options = ReportRenderingOptions.where(report_type: 'orders_and_distributors', report_subtype: nil) + + options.find_each do |option| + begin + fields_to_show = option.options[:fields_to_show] + next if fields_to_show&.exclude?('product') + + fields_to_show.delete('product') + fields_to_show << 'item_name' + option.update(options: option.options) + rescue StandardError => e + puts "Failed to revert rendering option with id: #{option.id}" + puts "Error: #{e.message}" + end + end + end +end