Update todos records that use WorkItem as the target_type value

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Todos created with TodoService are using the target's class name for the target_type column which results in inconsistencies when the target is a subclass like WorkItem.

[1] pry(main)> p, u, wi = Project.last, User.first, WorkItem.last
[2] pry(main)> todo1 = Todo.create!(target: wi, user: u, project: p, author: u, action: 2)
=> #<Todo:0x000000013db17b08
 id: 209,
 user_id: 1,
 project_id: 62,
 target_id: 1834,
 target_type: "Issue",
 author_id: 1,
 action: 2,
 state: "pending",
 created_at: Thu, 22 Jun 2023 10:00:50.426234000 UTC +00:00,
 updated_at: Thu, 22 Jun 2023 10:00:50.426234000 UTC +00:00,
 commit_id: nil,
 group_id: nil,
 resolved_by_action: nil,
 note_id: nil>
[3] pry(main)> todo2 = TodoService.new.mark_todo(wi, u)
=> [#<Todo:0x000000017d217298
  id: 211,
  user_id: 1,
  project_id: 61,
  target_id: 1834,
  target_type: "WorkItem",
  author_id: 1,
  action: 4,
  state: "pending",
  created_at: Thu, 22 Jun 2023 10:05:44.760159000 UTC +00:00,
  updated_at: Thu, 22 Jun 2023 10:05:44.760159000 UTC +00:00,
  commit_id: nil,
  group_id: nil,
  resolved_by_action: nil,
  note_id: nil>]

A fix for TodoService is included in !124081 (merged) so new records will be created correctly but we need to update existing records to use Issue instead of WorkItem.

Tasks

  • Add background migration to update todos where the target_type value is `WorkItem'.
  • Remove WorkItem#todoable_target_type_name method (see !124081 (comment 1441991457))
Edited by 🤖 GitLab Bot 🤖