From 04da91bf34e3a75121cd0c96654bfc615656e41f Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Wed, 20 Sep 2023 16:24:08 +0100 Subject: [PATCH] Add Rake task to migrate timeline events Since we're going to stop using the old_state and new_state fields and instead rely on the existing old_value and new_value fields. --- lib/tasks/timeline_events.rake | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/tasks/timeline_events.rake b/lib/tasks/timeline_events.rake index 13bceac257..4f3d15437c 100644 --- a/lib/tasks/timeline_events.rake +++ b/lib/tasks/timeline_events.rake @@ -1,8 +1,15 @@ namespace :timeline_events do - desc "Migrate state_changed events" - task migrate_state_changed: :environment do - TimelineEvent.where(event_type: "state_changed").update_all( - event_type: "status_changed", - ) + desc "Migrate old_state/new_state" + task migrate_old_new_state: :environment do + TimelineEvent + .where(event_type: %w[status_changed assessment_section_recorded]) + .each do |timeline_event| + timeline_event.update!( + old_value: timeline_event.old_state, + new_value: timeline_event.new_state, + old_state: "", + new_state: "", + ) + end end end