Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the data migration's left join update compatible #17355

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ class NullifyTargetsOnBsRequestActions < ActiveRecord::Migration[7.0]
# rubocop:disable Rails/SkipsModelValidations
def up
BsRequestAction
.joins('LEFT JOIN projects ON bs_request_actions.target_project_id = projects.id WHERE bs_request_actions.target_project_id IS NOT NULL AND projects.id IS NULL')
.left_joins(:target_project_object)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of the table name, we need to use the association name: this one

.where.not(bs_request_actions: { target_project_id: nil })
.where(projects: { id: nil })
.in_batches
.update_all(target_project_id: nil)

BsRequestAction
.joins('LEFT JOIN packages ON bs_request_actions.target_package_id = packages.id WHERE bs_request_actions.target_package_id IS NOT NULL AND packages.id IS NULL')
.in_batches
.update_all(target_package_id: nil)
.left_joins(:target_package_object)
.where.not(bs_request_actions: { target_package_id: nil })
.where(packages: { id: nil })
.in_batches.update_all(target_package_id: nil)
end
# rubocop:enable Rails/SkipsModelValidations

Expand Down