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

Add rake tasks to cleanup and backfill data in bs_request_actions table #17319

Conversation

rubhanazeem
Copy link
Member

@rubhanazeem rubhanazeem commented Jan 30, 2025

This PR introduces two new tasks, both of which modify the BsRequestActions table:

  1. bin/rails backfill_source to add source project/package_id
    Before executing the task make some calculations:
BsRequestAction.where(source_project_id: nil, source_package_id: nil).where('source_project IS NOT NULL OR source_package IS NOT NULL').count

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.

  1. bin/rails remove_target to remove target project/package association if they no longer exist.
BsRequestAction.where('target_project_id IS NOT NULL OR target_package_id IS NOT NULL').count

The count should increase after executing this task, indicating that target project/package associations that no longer exist have been removed.

@github-actions github-actions bot added the Frontend Things related to the OBS RoR app label Jan 30, 2025
@rubhanazeem rubhanazeem force-pushed the backfill-source_ids_in_request_action branch from 328f8fc to b85c3f6 Compare January 30, 2025 13:34
@rubhanazeem rubhanazeem marked this pull request as ready for review January 30, 2025 15:27
@hennevogel
Copy link
Member

Aren't those data migrations?

@rubhanazeem rubhanazeem force-pushed the backfill-source_ids_in_request_action branch from b85c3f6 to ff2aab6 Compare January 30, 2025 16:00
@rubhanazeem
Copy link
Member Author

rubhanazeem commented Jan 30, 2025

Aren't those data migrations?

We decided to keep this in task

@rubhanazeem rubhanazeem marked this pull request as draft January 30, 2025 16:48
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|
Copy link
Contributor

@danidoni danidoni Jan 31, 2025

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|
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

@eduardoj
Copy link
Member

I split this PR into two, converting the rake tasks to data migrations. See:

@hennevogel hennevogel closed this Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Frontend Things related to the OBS RoR app
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants