-
Notifications
You must be signed in to change notification settings - Fork 336
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
TypeDB 3.0: cascading deletes #7021
Labels
Milestone
Comments
flyingsilverfin
changed the title
TypeDB 3.0: Cascading deletes
TypeDB 3.0: cascading deletes
Apr 3, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem to Solve
Currently, users have to manage deletion of dependent/connected relations manually when deleting entities or relations.
Current Workaround
Users have to manually query for connected desired relations and delete them in a separate query, before deleting the concept itself.
Proposed Solution
Query-level cascades:
Allow specifying which types to cascade deletes into (polymorphically specifying is OK too!):
Note that
cascade
should cascade through relations recursively! In this example, if there areemployment
relations contained inemployment
relations, these should be recursively deleted as well.We could also consider an extension which only cascades if a constraint is violated:
Schema-level cascade
We consider using the SQL/postgres inspired specification at the schema level, which would be translated into specifying delete behaviour at the relation definition:
This annotation means the relation will be automatically deleted on cardinality violation.
This is contrasting to the default behaviour, where transaction commit would be rejected.
We should also help the user by introducing a query to check consistency of the data before commit, which will especially help with schema migrations and manual intervensions.
Within one transaction, we will allow cardinality to be violated, to allow mutating data in-place easily.
Extensions with greater flexibility
The
cascade
clause following adelete
is a bit like thefetch
clause: it makes the 95% common case extremely easy to express and use.However, there are cases which may require greater flexibility: we may not want to recursively delete all connected relations of the specified types, but maybe only within a limited range, or with other general conditions (connected to neighbors with a specific attribute, whatever):
We can achieve such a generalised form by combining a
match
clause usingtry
statements, with adelete
clause:Further, we could combine this with recursive query functions to traverse a specific depth of connected relations and delete these selectively.
The text was updated successfully, but these errors were encountered: