-
Notifications
You must be signed in to change notification settings - Fork 445
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
Add rake tasks to cleanup and backfill data in bs_request_actions table #17319
Add rake tasks to cleanup and backfill data in bs_request_actions table #17319
Conversation
328f8fc
to
b85c3f6
Compare
Aren't those data migrations? |
b85c3f6
to
ff2aab6
Compare
We decided to keep this in task |
desc('Insert source_project_id and source_package_id in bs_request_actions') | ||
task(backfill_source: :environment) do | ||
bs_request_actions = BsRequestAction.where(source_project_id: nil, source_package_id: nil).where('source_project IS NOT NULL OR source_package IS NOT NULL') | ||
bs_request_actions.find_each do |action| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you better use chunked iterators, or it will try to load the whole collection of elements in memory...
desc('Remove target_project_id and target_package_id from bs_request_actions if the projects and packages no longer exist') | ||
task(remove_target: :environment) do | ||
bs_request_actions = BsRequestAction.where('target_project_id IS NOT NULL OR target_package_id IS NOT NULL') | ||
bs_request_actions.find_each do |action| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
I split this PR into two, converting the rake tasks to data migrations. See: |
This PR introduces two new tasks, both of which modify the
BsRequestActions
table:bin/rails backfill_source
to add source project/package_idBefore executing the task make some calculations:
This query returns the number of records that need to be updated. Run it both before and after executing the task. Ideally, the count after execution should be significantly lower than before. However, some BsRequestAction records would remain unchanged if their sources have been removed. To verify that the task has been executed successfully, inspect a random subset of records.
bin/rails remove_target
to remove target project/package association if they no longer exist.The count should increase after executing this task, indicating that target project/package associations that no longer exist have been removed.