Improve update_all when FROM is a subquery
What does this MR do?
After working in !46260 (merged), we have learned that the UPDATE statement was incorrect because the SQL code doesn't include the subquery.
This change partially reverts the changes in c2b330dc.
This is not a bug because:
- If a project has an issue tracker integration or an external wiki
integration,
has_external_issue_tracker
/has_external_wiki
is alreadytrue
, so we just were updating it again withtrue
. This commit avoids this scenario. - If a project doesn't have an issue tracker integration or an external
wiki integration,
has_external_issue_tracker
/has_external_wiki
isfalse
, so we update it totrue
.
Example
Having the following database records, we have to create a Jira service on each project belonging to group 1 without the integration and we also have to update the has_external_issue_tracker = true
.
Project id: 1, has_external_issue_tracker: false, jira_service_id: nil, group: 1
Project id: 2, has_external_issue_tracker: true, jira_service_id: 1, group: 1
Project id: 3, has_external_issue_tracker: false, jira_service_id: nil, group: 2
Project id: 4, has_external_issue_tracker: false, jira_service_id: nil, group 1
If the UPDATE
statement doesn't include the subquery filtering by group:
Project
.where(id: Project.minimum(:id)..Project.maximum(:id))
.without_integration(integration)
.in_namespace(integration.group.self_and_descendants)
It's possible to update all the projects, setting has_external_issue_tracker = true
where it should not be updated for project 3.
Related to #268133 (closed)
Edited by Arturo Herrero