Backfill requirements_management_test_reports.issue_id column
What does this MR do and why?
Populate requirements_management_test_reports.issue_id column. This is part of the deprecation process of requirement_id column. Requirement model is going to be removed and
work items(issue with type requirement) will be used instead.
On #342496 (closed) a background migration ran to create issue objects for each requirement and keep them in sync until requirements can be fully removed, in order to do this we added an association between issues and requirements using issue_id column on requirements table. TestReport also has issue_id and requirement_id column, with this background migration we are populating TestReport#issue_id with parent Requirement#issue_id so requirement_id column can be removed later.
More information at #345841 (closed).
How to set up and validate locally
There is no way to validate this locally yet because TestReport does not have a fully functional UI. We just have to make sure that the following happens:
test_report.issue_id = test_report.requirement.requirement_issue.id
Can be verified on console or a database session.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Database queries
All id numbers and query plans were taken from production. With exception of the update query that ran on database lab.
Test reports to update
SELECT COUNT(*) FROM requirements_management_test_reports WHERE issue_id IS NULL \g
4511
I did set 2 minutes delay per batch of 30 records. Should take ~5 hours to finish.
Scheduling queries
SELECT "requirements_management_test_reports"."id" FROM "requirements_management_test_reports" WHERE "requirements_management_test_reports"."issue_id" IS NULL ORDER BY "requirements_management_test_reports"."id" ASC LIMIT 1
SELECT "requirements_management_test_reports"."id" FROM "requirements_management_test_reports" WHERE "requirements_management_test_reports"."issue_id" IS NULL AND "requirements_management_test_reports"."id" >= 1 ORDER BY "requirements_management_test_reports"."id" ASC LIMIT 1 OFFSET 30
SELECT MIN("requirements_management_test_reports"."id"), MAX("requirements_management_test_reports"."id") FROM "requirements_management_test_reports" WHERE "requirements_management_test_reports"."issue_id" IS NULL AND "requirements_management_test_reports"."id" >= 1 AND "requirements_management_test_reports"."id" < 31
Update query
UPDATE requirements_management_test_reports AS test_reports
SET issue_id = requirements.issue_id
FROM requirements
WHERE test_reports.requirement_id = requirements.id
AND test_reports.issue_id IS NULL
AND test_reports.id BETWEEN 1 AND 30
-
Numbers from database lab run:
The query has been executed. Duration: 152.844 ms (edited)
Time: 1.994 ms
- planning: 1.838 ms
- execution: 0.156 ms
- I/O read: 0.000 ms
- I/O write: 0.000 ms
Shared buffers:
- hits: 66 (~528.00 KiB) from the buffer pool
- reads: 0 from the OS file cache, including disk I/O
- dirtied: 0
- writes: 0