-
Notifications
You must be signed in to change notification settings - Fork 4
[PB-5670] fix/add migration to clean up duplicate backup folders with batching #852
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
base: master
Are you sure you want to change the base?
Conversation
|
explain result @sg-gs
|
0c3ca0a to
47ce568
Compare
47ce568 to
bbd6962
Compare
bbd6962 to
4ae1045
Compare
4ae1045 to
37c9be2
Compare
37c9be2 to
ccf78bc
Compare
ccf78bc to
ea983ee
Compare
sg-gs
left a comment
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.
Remember to add the tests to cover the case that produced this issue in the first place.
| SELECT 1 | ||
| FROM files | ||
| WHERE folder_id = f.id | ||
| AND deleted = false |
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.
use the status != 'DELETED' field, deleted and removed are deprecated
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.
addressed
| WITH duplicate_groups AS ( | ||
| SELECT | ||
| plain_name, | ||
| bucket, | ||
| user_id, | ||
| MIN(id) as id_to_keep | ||
| FROM folders | ||
| WHERE | ||
| created_at >= '2025-12-17 14:16:00' | ||
| AND created_at <= '2026-01-05 21:50:00' | ||
| AND parent_id IS NULL | ||
| AND parent_uuid IS NULL | ||
| AND deleted = false | ||
| AND removed = false | ||
| AND plain_name IS NOT NULL | ||
| GROUP BY plain_name, bucket, user_id | ||
| HAVING COUNT(*) > 1 | ||
| LIMIT ${BATCH_SIZE} | ||
| ), |
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.
This gets the oldest folder from each duplicated group. So we should be getting 905 folders from this cte
| folders_to_delete AS ( | ||
| SELECT f.id | ||
| FROM folders f | ||
| INNER JOIN duplicate_groups dg | ||
| ON f.plain_name = dg.plain_name | ||
| AND f.bucket = dg.bucket | ||
| AND f.user_id = dg.user_id | ||
| WHERE | ||
| f.id != dg.id_to_keep | ||
| AND NOT EXISTS ( | ||
| SELECT 1 | ||
| FROM files | ||
| WHERE folder_id = f.id | ||
| AND deleted = false | ||
| ) | ||
| ) |
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.
this joins all folders back to their duplicate group by matching (plain_name, bucket, user_id). So if a group has 3 duplicates, the JOIN produces 3 rows — each with that group's id_to_keep. Then we filter to only keep folders where:
- id != id_to_keep (not the oldest/keeper)
- No direct files (status != 'DELETED')
- No child folders (deleted = false)
this should get 5863 folders
… and enhance test coverage for folder creation
…m duplicate backup folder deletion
|
|
This PR is stale because it has been open for more than 15 days with no activity. |



Cleanup script to remove duplicated backup root folders