mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
Add rake task for resources
This commit is contained in:
parent
e73baa2754
commit
6c7e8bc8a1
1 changed files with 12 additions and 0 deletions
12
lib/tasks/normalize_resources.rake
Normal file
12
lib/tasks/normalize_resources.rake
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue