calculate duration for existing work packages

pull/10645/head
ulferts 2 years ago
parent 2d3457388a
commit 841ec88490
No known key found for this signature in database
GPG Key ID: A205708DE1284017
  1. 23
      db/migrate/20220525154549_add_duration_to_work_packages.rb

@ -3,5 +3,28 @@ class AddDurationToWorkPackages < ActiveRecord::Migration[6.1]
add_column :work_packages, :duration, :integer
add_column :work_package_journals, :duration, :integer
reversible do |dir|
dir.up do
set_duration(:work_packages)
set_duration(:work_package_journals)
end
end
end
private
def set_duration(table)
execute <<~SQL.squish
UPDATE
#{table}
SET
duration = CASE
WHEN start_date IS NULL OR due_date IS NULL
THEN 1
ELSE
due_date - start_date + 1
END
SQL
end
end

Loading…
Cancel
Save