mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
12878: add migration to show new column product column
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user