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

Cleanup command #1124

Open
Nemo64 opened this issue May 3, 2020 · 4 comments
Open

Cleanup command #1124

Nemo64 opened this issue May 3, 2020 · 4 comments

Comments

@Nemo64
Copy link
Contributor

Nemo64 commented May 3, 2020

Feature Request

Q A
New Feature yes
RFC no
BC Break no

Summary

In a relation database it is quiet easy to implicitly delete a row throw foreign key constraints without doctrine noticing.

I want to propose a cleanup command that goes through all mapped entities and all existing files and tries to delete all files that are orphaned.

I could implement this for doctrine orm but I'm not fluent in the other storage engines.

I also see that this could become challenging if the amount of files goes above ~65.535 and even before that, it probably should work in chunks to avoid loading everything into ram.

@garak
Copy link
Collaborator

garak commented May 3, 2020

I think that getting orphaned Doctrine objects does not belong here.
You should execute such task elsewhere, while deleting a mapped object should already delete related file.

@Nemo64
Copy link
Contributor Author

Nemo64 commented May 3, 2020

Maybe I described it the wrong way.

I'm not talking about orphaned doctrine objects, I'm talking about orphaned files.
If you have a relation defined with @JoinColumn(onDelete="CASCADE"). then the database can delete rows without doctrine knowing about it and therefore without this bundle deleting the corresponding files.
And there might also be external sources deleting rows, maybe even accidents or manual cleanup.
That's why I would like an easy way to check if the the database and the filesystem are in sync.

@garak
Copy link
Collaborator

garak commented May 3, 2020

Oh well, in that case it looks fine to me.
Waiting for your PR

@UlrichThomasGabor
Copy link
Contributor

Doctrine has cascade={'remove'} which cascades on the Doctrine level instead on the DB level:
https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/working-with-associations.html#transitive-persistence-cascade-operations

Might still make sense have a command to check data consistency though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants