Backfill the prepared_at column for merge requests
What does this MR do and why?
Currently, when the merge requests are prepared, we set the prepared_at
on the column for the merge request.
We need to back fill all the previous merge requests that don't have this set. However, there will be a potential issue where someone creates a new MR, which doesn't have a prepared_at, and this may potentially get picked up in this background migration. To avoid this, we use when it is not of merge_status
state of preparing
to filter these out.
To Test:
- Create an MR
- Set the prepared_at to nil
- Run migration
- Check the prepared_at is equal to created_at
Related to: #391708 (closed)
Database Information:
Update of a batch of 1000 ID's SQL
UPDATE "merge_requests" SET prepared_at = created_at WHERE "merge_requests"."id" BETWEEN 1 AND 1000 AND "merge_requests"."prepared_at" IS NULL AND "merge_requests"."merge_status" != 'preparing' AND "merge_requests"."id" >= 1 AND "merge_requests"."id" < 1000
ModifyTable on public.merge_requests (cost=0.57..411.46 rows=772 width=835) (actual time=14359.125..14359.127 rows=0 loops=1)
Buffers: shared hit=142636 read=8263 dirtied=3914 written=57
I/O Timings: read=13680.348 write=0.000
-> Index Scan using merge_requests_pkey on public.merge_requests (cost=0.57..411.46 rows=772 width=835) (actual time=2.351..297.648 rows=774 loops=1)
Index Cond: ((merge_requests.id >= 1) AND (merge_requests.id <= 1000) AND (merge_requests.id >= 1) AND (merge_requests.id < 1000))
Filter: ((merge_requests.prepared_at IS NULL) AND ((merge_requests.merge_status)::text <> 'preparing'::text))
Rows Removed by Filter: 0
Buffers: shared hit=103 read=195 dirtied=1
I/O Timings: read=291.316 write=0.000
Explain of an update: https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/15581/commands/53878
Edited by Marc Shaw