chained deletes
Hey Convex! I just wanted to ask a quick question before I go down a logic rabbit hole... Does convex provide any sort of helpers / convenience for a sort of "cascade/relational delete"? Rather than needing to write some unwieldy functions that tear apart related data, I am hoping/wishing for some sort of function that is essentially "Given this ID, delete it and anything related to it" so that I don't have to worry about orphaned data, and I don't have to rely on finicky chained deletes that could have lots of points of failure
2 Replies
convex-ents is a library that supports cascading deletes https://stack.convex.dev/ents
however, i'm not sure what you mean by this:
I don't have to rely on finicky chained deletes that could have lots of points of failureconvex mutations are transactions, so they won't have many points of failure. if they fail, the transaction doesn't commit so nothing happened. if they succeed, everything succeeded
Convex Ents: Manage your document relationships
Convex Ents is a library that provides: simpler ways to model and query related documents, ability to easily map and filter documents, enforcing uniqu...
keep in mind gotchas with cascading deletes discussed in Ents: https://labs.convex.dev/convex-ents/schema/deletes
Specifically, they often aren't what you want for deleting entities that might have thousands of records. For one, that's a huge transaction that needs to be broken up. Secondly, you can accidentally delete a ton of data that you might not have meant to. For instance, when a user leaves a team in Slack, you still want to see all their messages. When a user deletes a whole team, you probably want to keep it around for a few days in case they write in saying it was a mistake. Treating deletes as soft deletes / moves to a "deletedFoo" table / etc. is how it's done at scale.
Cascading Deletes - Convex Ents
Relations, default values, unique fields and more for Convex