permanentDeleteCard
Permanently deletes a card and all associated files from storage. This operation is irreversible.Soft delete vs. permanent delete: Teak supports soft deletion (trash/recycle bin) via the
updateCardField mutation with field: "delete". Use permanentDeleteCard only when you want to completely remove a card and free up storage space.Arguments
The unique identifier of the card to permanently delete.
Returns
Returns
null on successful deletion. Throws an error if the operation fails.Behavior
Authorization Check
Authorization Check
File Cleanup
File Cleanup
Automatically deletes associated files from Convex storage:
- Main file (
fileId): Original uploaded file (image, video, audio, document) - Thumbnail (
thumbnailId): Generated or custom thumbnail image
ctx.storage.delete(), which:- Removes the file from storage immediately
- Invalidates all signed URLs for the file
- Frees up storage quota
metadata.linkPreview are NOT automatically deleted. These are referenced by imageStorageId and screenshotStorageId but are not covered by the current implementation.Database Removal
Database Removal
After file cleanup, the card document is permanently removed from the database:This operation:
- Removes the card from all indexes
- Makes the card ID invalid for future queries
- Cannot be undone or restored
Idempotency
Idempotency
The function is not idempotent:
- First call: Deletes the card successfully
- Subsequent calls: Throw “Card not found” error
Error Handling
Thrown when attempting to delete without an authenticated session.
Thrown when the card ID doesn’t exist in the database.This can occur if:
- Card was already deleted
- Invalid card ID was provided
- Card was deleted by another concurrent operation
Thrown when the authenticated user doesn’t own the card.Cards can only be deleted by their owner (matched by
userId).Best Practices
Soft Delete First
Soft Delete First
Implement a two-step deletion flow:
- First click: Soft delete using
updateCardField({ field: "delete" })- Moves card to trash/recycle bin
- Allows user to restore if needed
- Sets
isDeleted: trueanddeletedAt: timestamp
- Second click (from trash): Permanent delete using
permanentDeleteCard- Shows confirmation dialog
- Warns about irreversibility
- Completely removes card and files
Confirmation Dialog
Confirmation Dialog
Always show a confirmation dialog before permanent deletion:
Batch Deletion
Batch Deletion
When deleting multiple cards, handle errors gracefully:Consider implementing batch operations in parallel:
Storage Cleanup
Storage Cleanup
The function currently deletes
fileId and thumbnailId, but not:- Link preview images (
metadata.linkPreview.imageStorageId) - Link preview screenshots (
metadata.linkPreview.screenshotStorageId)
Workflow Example
Source Reference
Implemented inpackages/convex/card/deleteCard.ts:4