Make set_original_heading_id task idempotent

This way there'll be no side effects if accidentally executed on data
already having the `original_heading_id`.
This commit is contained in:
Javi Martín
2019-10-08 03:24:00 +02:00
parent acbad38749
commit 4fad6f16f6
2 changed files with 17 additions and 1 deletions

View File

@@ -17,7 +17,9 @@ namespace :budgets do
task set_original_heading_id: :environment do
puts "Starting"
Budget::Investment.find_each do |investment|
investment.update_column(:original_heading_id, investment.heading_id)
unless investment.original_heading_id.present?
investment.update_column(:original_heading_id, investment.heading_id)
end
print "."
end
puts "Finished"