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

Cascading delete (remove related entities / references when deleting an entity) #220

Closed
liwde opened this issue Jan 23, 2019 · 10 comments · Fixed by #2041
Closed

Cascading delete (remove related entities / references when deleting an entity) #220

liwde opened this issue Jan 23, 2019 · 10 comments · Fixed by #2041
Assignees
Labels
released on @master managed by CI (semantic-release) released managed by CI (semantic-release) Type: Feature new user-facing feature Type: Refactoring / Technical Enh. Technical Enhancement without changes for the user

Comments

@liwde
Copy link
Contributor

liwde commented Jan 23, 2019

Issue Summary

When deleting an entity that is referenced in other entities (e.g. its id is stored in Note entities, etc.), we are currently neither deleting these related records nor removing the reference. This leads to dead references and subsequently to errors (see #874). We therefore need to implement a more sophisticated delete functionality.

Requirements:

  • ? id of deleted entity is removed from any other record that remains in the database (e.g. Notes referencing a deleted child are edited and that id is removed from the Note)
  • ? cascading delete: related entities can be deleted automatically together with the primary entity that is deleted (e.g. all ChildSchoolRelation entities for a child are deleted when that child is deleted)
    • how to configure this or ask the user whether to do a cascading delete?

Possible approaches:

  • ?

original comment

As discussed in #218, currently we do not look at foreign key relationships when deleting entities at all. When someone deletes e.g. a child, the notes relating to that child keep the reference to a (now deleted) Entity causing some errors. Aside from the error-handling, we should also focus on this root-issue.

I can imagine that a feasible workaround would be to extend entity.ts to have some (abstract) lifecycle-method onBeforeDelete(em: EntityMapperService), where each Entity-Subclass (like Child) can define steps to remove foreign references through the EntityMapperService passed as an argument.

This should work relatively independent of the Database layer just within our Entity system. It should be especially easy for Entities like ChildSchoolRelation that should be deleted with the Child.

What are your thoughts on this?

@liwde liwde added Type: Refactoring / Technical Enh. Technical Enhancement without changes for the user Status: Idea to be considered and discussed - don't start work yet labels Jan 23, 2019
@Lorsbyjm
Copy link
Contributor

I am not really in to the EntityMapperService, but we should definetly not have "dead" relations. The sougesstion sounds good and not to complicated

@sleidig
Copy link
Member

sleidig commented Feb 14, 2019

This is somewhat related to the overall topic of how we manage related entities in the database (#108). But relational-pouch doesn't seem to offer this at the moment either pouchdb-community/relational-pouch#82

@sleidig
Copy link
Member

sleidig commented Feb 14, 2019

If we implement a cascading delete of related records, we should consider restricting the rights to delete to admins only. Anyway, deletion is usually something users wouldn't want, as they loose all the context. Archiving entities (i.e. flagging them to be hidden) would often be a better option, I guess.

@sleidig sleidig changed the title Handle Foreign Keys in our Database / Entity Model Handle Foreign Keys in our Database / Entity Model (e.g. for cascading delete) Jul 16, 2019
@sleidig sleidig added this to the Ideas milestone Feb 18, 2020
@sleidig sleidig removed this from the Ideas milestone Sep 8, 2020
@sleidig
Copy link
Member

sleidig commented Dec 7, 2020

For ChildSchoolRelations (and maybe some other types of entities) there is really no point to keep them if a child is indeed deleted. So at least for some entities this cascading delete is needed (#547), while for other entities deleting in general may not be wanted (#371).

@sleidig sleidig changed the title Handle Foreign Keys in our Database / Entity Model (e.g. for cascading delete) Cascading delete (delete / remove reference when deleting an entity) Sep 21, 2023
@sleidig sleidig added Type: Feature new user-facing feature Status: Needs Details/Concept and removed Status: Idea to be considered and discussed - don't start work yet labels Sep 21, 2023
@sleidig sleidig changed the title Cascading delete (delete / remove reference when deleting an entity) Cascading delete (remove related entities / references when deleting an entity) Sep 21, 2023
@sleidig
Copy link
Member

sleidig commented Sep 22, 2023

Use case scenarios & requirement specifications:

When deleting a ("primary") entity P there may be the following related scenarios:

P has a property that references another entity

  • --> not problematic. The reference is lost but that can be assumed an intended consequence of the user action. There will not be any "dead references" left in the database from this.

P is referenced by another ("secondary") entity S1 (exclusively, i.e. that secondary entity does not reference any further entities)

  • the secondary entity S1 should also be deleted (?) as it exclusively relates to the deleted entity
  • ❓ is there any use case where we would want to just delete the referenced id but keep S1?
    • for Notes, etc. it doesn't seem to be relevant usually
    • maybe we should make this configurable by flagging the schema field as "essential" or not (see below)
  • the user should be warned in the confirmation dialog that these related records are removed as well.

P is referenced by another entity S2, where P is the only reference in that property but S2 has another property that also references some other entity

  • e.g. a Note referencing only P in children but another entity in schools
  • for Notes I would treat this as a case of S3 (i.e. keep the secondary record)
  • but for ChildSchoolRelation the schema technically looks similar but we would want to delete that record
    • maybe this requires configuration in the schema which references are "primary"? (see below)

P is referenced by another entity S3 which also references other primary entities in the same property

  • e.g. a Note referencing multiple children, one of which is P, being deleted now
  • --> remove the id of P from the references array and keep S3 in the database
  • ❓ in case of deleting the record for data protection reasons, this might be problematic / require manual review of the user: a Note may well contain very sensitive and clearly identifiable information referring to P in the Note text that remains in the database even though the formal record and reference are removed (same is true for a possible "cascading anonymization")

Configurable role/importance of an entity reference property?

Should we make entity reference properties in the schema configurable to flag their importance? e.g.

  • primary: reference is essential, when removed, the whole entity should be deleted as well
  • secondary: reference is providing additional information, when the referenced is delete, remove the referenced id but keep this entity
  • review: manual review? (see below)
  • what would be default behavior? = secondary?

example schema: { dataType: "entity", role: "primary" }

ChildSchoolRelation: childId = primary & schoolId = primary
--> if either one is deleted, the ChildSchoolRelation also gets deleted

Manual review of referenced secondary entities?

Use case: A note is referencing multiple children. The text contains sensitive personal information about each of the children. The user now deletes one of the referenced Child entities.

This is a case of S3 and we very likely should not delete that note (the other referenced children are still in the database).
However, if P is deleted out of data protection concerns (e.g. a GDPR data deletion request), that note's text would need to be edited.

Is it feasible to show the user certain related entities to decide case by case to update or delete them?
UX seems difficult for that. But how to ensure sensitive data is properly removed?

Possible approaches:

  • Refuse to delete the primary entity as long as such related entities exist
    • user has to go through the record and either remove the link to the entity or delete the related entity completely
    • after that, can click "delete" for P again and go ahead with the deletion
  • Show each related entity one by one to the user for review
    • user can update (e.g. remove details from text and save the note), delete or keep
    • what happens if the user "aborts" that process with a long queue of secondary entities to be reviewed?
  • Flag such related entities and provide a view that lists these for the user to review and clear

in case of anonymization: (how) could the user flag a note as "text is clear of personal data about P" without removing the link completely (e.g. to keep the record of someone having participated in an event)?

also see scenarios for anonymization: #1674 (comment)

@TheSlimvReal
Copy link
Collaborator

Good collection of the possible cases. I agree with the 3 roles even though I expect it to be very difficult to build a good review workflow that brings the user through all data.
What I am not sure now with your idea of primary and secondary: I imagine the children property of a note to be of role secondary (especially for group notes). What if all children that were referenced in a note where deleted? secondary would keep the note but remove all the IDs. While for a group note this might make sense, for notes just linked with one entity this should probably be deleted once the child is deleted.
So maybe to property would rather be primary and we define the rules of primary as delete entity if no other references are in this property array are left and otherwise behave like secondary?

@sleidig
Copy link
Member

sleidig commented Sep 29, 2023

cascading-delete

@sleidig sleidig moved this from Triage to In Progress in All Tasks & Issues Oct 2, 2023
@sleidig sleidig self-assigned this Oct 5, 2023
@sleidig
Copy link
Member

sleidig commented Oct 16, 2023

when implementing this, revisit the current (incomplete) logic of anonymize: #2012 (comment)

This was referenced Oct 16, 2023
@sleidig sleidig moved this from In Progress to In Review in All Tasks & Issues Oct 23, 2023
@github-project-automation github-project-automation bot moved this from In Review to Done in All Tasks & Issues Nov 19, 2023
sleidig added a commit that referenced this issue Nov 19, 2023
closes #220

---------
This functionality has been developed for the project “codo”.
codo is developed under the projects “Landungsbrücken – Patenschaften in Hamburg stärken” and “openTransfer Patenschaften”. It is funded through the program “Menschen stärken Menschen” by the German Federal Ministry of Family Affairs, Senior Citizens, Women and Youth.
More information at https://github.com/codo-mentoring

“Landungsbrücken – Patenschaften in Hamburg stärken” is a project of BürgerStiftung Hamburg in cooperation with the Mentor.Ring Hamburg. With a mix of networking opportunities, capacity building and financial support the project strengthens Hamburg’s scene of mentoring projects since its founding in 2016.

The “Stiftung Bürgermut” foundation since 2007 supports the digital and real exchange of experiences and connections of active citizens. Within the federal program “Menschen stärken Menschen” the foundation as part of its program “openTransfer Patenschaften” offers support services for connecting, spreading and upskilling mentoring organisations across Germany.

Diese Funktion wurde entwickelt für das Projekt codo.
codo wird entwickelt im Rahmen der Projekte Landungsbrücken – Patenschaften in Hamburg stärken und openTransfer Patenschaften. Er ist gefördert durch das Bundesprogramm Menschen stärken Menschen des Bundesministeriums für Familie, Senioren, Frauen und Jugend.
Mehr Informationen unter https://github.com/codo-mentoring

“Landungsbrücken – Patenschaften in Hamburg stärken” ist ein Projekt der BürgerStiftung Hamburg in Kooperation mit dem Mentor.Ring Hamburg. Mit einer Mischung aus Vernetzungsangeboten, Qualifizierungsmaßnahmen und finanzieller Förderung stärkt das Projekt die Hamburger Szene der Patenschaftsprojekte seit der Gründung im Jahr 2016.

Die Stiftung Bürgermut fördert seit 2007 den digitalen und realen Erfahrungsaustausch und die Vernetzung von engagierten Bürger:innen. Innerhalb des Bundesprogramms „Menschen stärken Menschen” bietet die Stiftung im Rahmen ihres Programms openTransfer Patenschaften Unterstützungsleistungen zur Vernetzung, Verbreitung und Qualifizierung von Patenschafts- und Mentoringorganisationen bundesweit.

Co-authored-by: codo-mentoring <117934638+codo-mentoring@users.noreply.github.com>
Co-authored-by: Simon <simon@aam-digital.com>
@aam-digital-ci
Copy link
Collaborator

🎉 This issue has been resolved in version 3.26.0-master.21 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@aam-digital-ci aam-digital-ci added the released on @master managed by CI (semantic-release) label Nov 19, 2023
@aam-digital-ci
Copy link
Collaborator

🎉 This issue has been resolved in version 3.26.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@aam-digital-ci aam-digital-ci added the released managed by CI (semantic-release) label Nov 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released on @master managed by CI (semantic-release) released managed by CI (semantic-release) Type: Feature new user-facing feature Type: Refactoring / Technical Enh. Technical Enhancement without changes for the user
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants