As a midway point to #11113, we created subclasses for each Colocated task action in #11295. The next step in #9057 is to migrate all ColocatedTasks in production to their new subclasses.
This can be done by updating the type of the task.
task.update!(type: ColocatedTask.find_subclass_by_action(task.action.to_s).name)
ColocatedTasks in production to their respective subclassThis will require some degree of ongoing monitoring - be aware that code elsewhere may be relying on the existing task type.
We should be able to remove the action column from the tasks table after we do this migration #9057.
Do we want update action to nil? Maybe we can do that in a second pass, so we still have the information if we mess anything up in the first pass.
Let's quickly see if we can get an idea of how many tasks this will update. Looker first: https://caseflow-looker.va.gov/sql/mrrydzw4m9pxcz
| count | action | type
--- | --- | ---
3726 | other | ColocatedTask
3209 | schedule_hearing | ColocatedTask
1828 | foia | ColocatedTask
1587 | extension | ColocatedTask
1141 | hearing_clarification | ColocatedTask
1070 | ihp | ColocatedTask
651 | poa_clarification | ColocatedTask
616 | aoj | ColocatedTask
397 | missing_hearing_transcripts | ColocatedTask
373 | missing_records | ColocatedTask
299 | address_verification | ColocatedTask
289 | translation | ColocatedTask
94 | new_rep_arguments | ColocatedTask
93 | arneson | ColocatedTask
33 | pending_scanning_vbms | ColocatedTask
22 | retired_vlj | ColocatedTask
16 | unaccredited_rep | ColocatedTask
How many total? https://caseflow-looker.va.gov/sql/6ztd5225pwncpf
15444
# Let's dry run this and see how many of each type of task gets changed.
rails c> Task.where(type: ColocatedTask.name).count
# 15444
# Numbers match. Fantastico!
# First let's group by ColocatedTask action field to confirm numbers are the same
rails c> pp Task.where(type: ColocatedTask.name).group(:action).count
# {"aoj"=>616,
"missing_records"=>373,
"retired_vlj"=>22,
"ihp"=>1070,
"unaccredited_rep"=>16,
"arneson"=>93,
"new_rep_arguments"=>94,
"missing_hearing_transcripts"=>397,
"schedule_hearing"=>3209,
"pending_scanning_vbms"=>33,
"poa_clarification"=>651,
"translation"=>289,
"other"=>3726,
"extension"=>1587,
"foia"=>1828,
"address_verification"=>299,
"hearing_clarification"=>1141}
# Look good!
# Now let's try to match each one up to the correct new type and confirm that they will
# all have a home!
rails c> Task.where(type: ColocatedTask.name).group(:action).keys
# Do each of these exist in our mapping?
rails c> type_for_action = Task.where(type: ColocatedTask.name).group(:action).count.keys.map do |action|
[action, ColocatedTask.find_subclass_by_action(action.to_s).name]
end.to_h
rails c> pp type_for_action
# {"aoj"=>"AojColocatedTask",
"missing_records"=>"MissingRecordsColocatedTask",
"retired_vlj"=>"RetiredVljColocatedTask",
"ihp"=>"IhpColocatedTask",
"unaccredited_rep"=>"UnaccreditedRepColocatedTask",
"arneson"=>"ArnesonColocatedTask",
"new_rep_arguments"=>"NewRepArgumentsColocatedTask",
"missing_hearing_transcripts"=>"MissingHearingTranscriptsColocatedTask",
"schedule_hearing"=>"ScheduleHearingColocatedTask",
"pending_scanning_vbms"=>"PendingScanningVbmsColocatedTask",
"poa_clarification"=>"PoaClarificationColocatedTask",
"translation"=>"TranslationColocatedTask",
"other"=>"OtherColocatedTask",
"extension"=>"ExtensionColocatedTask",
"foia"=>"FoiaColocatedTask",
"address_verification"=>"AddressVerificationColocatedTask",
"hearing_clarification"=>"HearingClarificationColocatedTask"}
# This number should not change:
rails c> ColocatedTask.count
# 16635
# This number should go to zero:
rails c> Task.where(type: ColocatedTask.name).count
# 15444
# These numbers should stay the same as well.
rails c> ColocatedTask.where.not(action: nil).count
# 15444
# These are all the new pups we've created.
rails c> ColocatedTask.where(action: nil).count
# 1193
# Let's make the change!
rails c> counts = type_for_action.keys.map { |action| [action, 0] }.to_h
rails c> Task.where(type: ColocatedTask.name).each do |task|
counts[task.action] += 1
end.map(&:id)
rails c> pp counts
rails c> counts_by_type = type_for_action.values.map { |action| [action, 0] }.to_h
rails c> Task.where(type: ColocatedTask.name).each do |task|
new_type = type_for_action[task.action]
counts_by_type[new_type] += 1
end.map(&:id)
rails c> pp counts_by_type
# {"AojColocatedTask"=>616,
"MissingRecordsColocatedTask"=>373,
"RetiredVljColocatedTask"=>22,
"IhpColocatedTask"=>1070,
"UnaccreditedRepColocatedTask"=>16,
"ArnesonColocatedTask"=>93,
"NewRepArgumentsColocatedTask"=>94,
"MissingHearingTranscriptsColocatedTask"=>397,
"ScheduleHearingColocatedTask"=>3209,
"PendingScanningVbmsColocatedTask"=>33,
"PoaClarificationColocatedTask"=>651,
"TranslationColocatedTask"=>289,
"OtherColocatedTask"=>3726,
"ExtensionColocatedTask"=>1587,
"FoiaColocatedTask"=>1828,
"AddressVerificationColocatedTask"=>299,
"HearingClarificationColocatedTask"=>1141}
# Let's actually make the change now!
rails c> Task.where(type: ColocatedTask.name).each do |task|
new_type = type_for_action[task.action]
task.update!(type: new_type)
end.map(&:id)
# Let's check that this worked out as we expected
# This number should still be 16635 (maybe a few more have been created since we last checked?)
rails c> ColocatedTask.count
# 16649
# Perfect.
# This number should have gone to zero:
rails c> Task.where(type: ColocatedTask.name).count
# 0
# This number should be the same as before.
rails c> ColocatedTask.where.not(action: nil).count
# 15444
# These are all the new pups we've created. Should be 14 larger: 1207
rails c> ColocatedTask.where(action: nil).count
# 1205
# Close enough. Maybe a pair was created between when we got this number and the previous one.
Let's check back on this puppy next week to make sure we aren't creating any ColocatedTasks anywhere and everything is hunky-dory!
No more pure ColocatedTasks remain! Looker results here. Closing this ticket since the migration is complete!
Most helpful comment
No more pure
ColocatedTasks remain! Looker results here. Closing this ticket since the migration is complete!