osem-fcy/lib/tasks/normalize_resources.rake

15 lines
477 B
Ruby
Raw Permalink Normal View History

# frozen_string_literal: true
2017-04-05 01:31:05 +05:30
namespace :data do
desc 'Update resources with nil quantity/used fields'
task normalize_resources: :environment do
Resource.where('used is ? or quantity is ?', nil, nil).each do |resource|
resource.used = 0 if resource.used.blank?
resource.quantity = resource.used if resource.quantity.blank?
unless resource.save
puts "Failed to update resource #{resource.name} (ID #{resource.id})"
end
end
end
end