tasks: repair updated_at of dossiers wrongly touched by PJ migration
When running the PJ migration task, migrated dossiers have their updated_at attribute modified. This means a yellow notification badge pops up on the Instructeurs pages. This PR repairs the affected dossiers, by restoring an approximative updated_at from the latest workflow value (or the timestamp of the migrated champ).
This commit is contained in:
parent
e0d2a31880
commit
0b49e61ec0
2 changed files with 67 additions and 0 deletions
|
@ -0,0 +1,19 @@
|
|||
require Rails.root.join("lib", "tasks", "task_helper")
|
||||
|
||||
namespace :fix_timestamps_of_migrated_dossiers do
|
||||
desc 'Fix the timestamps of dossiers affected by the faulty PJ migration'
|
||||
task run: :environment do
|
||||
affected_time_range = Time.utc(2019, 6, 4, 8, 0)..Time.utc(2019, 6, 4, 18, 0)
|
||||
dossiers = Dossier.unscoped.where(procedure_id: 0..1000).where(updated_at: affected_time_range)
|
||||
|
||||
progress = ProgressReport.new(dossiers.count)
|
||||
|
||||
dossiers.find_each do |dossier|
|
||||
fixed_updated_at = dossier.processed_at || dossier.en_instruction_at || dossier.en_construction_at || dossier.champs.last.updated_at || nil
|
||||
dossier.update_column(:updated_at, fixed_updated_at)
|
||||
|
||||
progress.inc
|
||||
end
|
||||
progress.finish
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue