Automatically delete related Convex documents in one call using your existing indexes to define parent-child relationships.
npm install @sholajegede/convex-cascading-deletesDrop-in Convex component for cascading deletes across related documents. Declare relationships once using your existing indexes, then call deleteWithCascade() instead of ctx.db.delete(). Dependents are recursively found and deleted in scheduler-batched mutations — atomic per batch. Includes a getSafeDb() helper that patches ctx.db to throw on direct deletes, a reactive deletion log queryable via useQuery, circular relationship protection, and index validation at startup.
The Cascading Deletes component lets you delete a user and cascade to all their posts, comments, and other related records automatically. Configure relationships via your existing indexes, then call deleteWithCascade() instead of manual cleanup across multiple tables.
While Convex doesn't have built-in foreign key constraints, this component provides referential integrity through cascading deletes. Define parent-child relationships using your existing indexes and ensure dependent records are always cleaned up when parents are deleted.
Large deletion trees are automatically processed in batches via the Convex scheduler, with atomic guarantees within each batch. The component handles the complexity of recursive dependency resolution and maintains deletion logs for audit purposes.
The Cascading Deletes component includes built-in circular relationship protection using visited tracking to prevent infinite loops. This ensures that complex relationship graphs with circular dependencies can be safely deleted without causing stack overflows or endless deletion cycles.
No schema changes are required. The Cascading Deletes component uses your existing indexes to define relationships between tables. You simply configure which indexes represent parent-child relationships and the component handles the rest automatically.
Deletions within each scheduler batch are atomic, so partial batches won't leave your database in an inconsistent state. If a batch fails, only that specific batch is rolled back while previous successful batches remain committed. The component logs all operations for audit and debugging purposes.
Yes, the Cascading Deletes component maintains a reactive deletion log that tracks every cascade operation with per-table counts and timestamps. You can query this log using useQuery to see exactly which records were deleted and when the cascade ran.