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

Allow cascading deletion of tree nodes and unused children #5324

Draft
wants to merge 5 commits into
base: production
Choose a base branch
from

Conversation

grantfitzsimmons
Copy link
Member

Fixes #1653

Rather than protecting children, the delete will cascade if there are no references to those children.

If all child nodes are not referenced by any records within that discipline (taxon, geography, lithostrat, chronostrat, tectonicunit) or institution (storage), then the user should be able to delete the parent and all children:
https://github.com/user-attachments/assets/1b8054b2-db58-4945-a27f-f1eb15b69475

If any child is referenced by a record within that discipline or institution, it should block deletion:
https://github.com/user-attachments/assets/ebdb649a-b57d-4596-89be-c7b094e1bfa2

TO BE DONE

Before this is merged or tested, we should consider this:

If it's not in a migration, the historical models that Django makes when running migrations will never have that on_delete functionality.

When running migrations, we (should) use an app registry which creates "fake" models at the migration runtime which have the fields and changes from all previously ran migrations, but not any future migrations (schema migrations - operations that add/alter tables and columns - do this implicitly)

It generates these based on the migration files themselves, so if we never include the change in a migration file the "fake" models in migrations will still think the on_delete functionality for trees is protect_with_blockers. So any migrations we write would have to still account for the old functionality: there will be a disconnect from the migration version of the model and the application version of the model

Testing instructions

Tip: To find unused nodes, make the counts climb up the entire tree: https://discourse.specifysoftware.org/t/change-tree-node-count-behavior/2014/1

  • If all child nodes are not referenced by any records within that discipline (taxon, geography, lithostrat, chronostrat, tectonicunit) or institution (storage), then the user should be able to delete the parent and all children.
  • If any child nodes are used, deletion should be blocked.

Rather than protecting children, the delete will cascade if there are no references to those children.
@grantfitzsimmons grantfitzsimmons changed the base branch from production to issue-5317 October 17, 2024 20:41
Base automatically changed from issue-5317 to production October 21, 2024 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 📋Back Log
Development

Successfully merging this pull request may close these issues.

Unable to delete unused parent and children at once in the trees
1 participant