Backfill merged_at column for merged merge requests
In the following issue: #412446 (closed) - it is mentioned that the merged_at is sometimes being returned null from the API, as it only reads a specific attribute, rather than handling all the cases that we need to due to the information being distorted over the years.
To make this more streamlined, it would be ideal that we have the correct data in the single attribute, and allow us to call simply this.
Currently we need to look at 4 different things to ensure a merged_at:
metrics&.merged_at ||
merge_event&.created_at ||
resource_state_events.find_by(state: :merged)&.created_at ||
notes.system.reorder(nil).find_by(note: 'merged')&.created_at
Ideally, we can just look at merge_request.metrics&.merged_at, but to do this requires us to backfill data.
Edited by Marc Shaw