mirror of
https://github.com/openSUSE/osem.git
synced 2026-01-02 11:09:30 -05:00
15 lines
477 B
Ruby
15 lines
477 B
Ruby
# frozen_string_literal: true
|
|
|
|
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
|