deleteUserData
Permanently removes all data associated with the specified user from the database.
This method performs a comprehensive data deletion operation, removing the user's container state and all historical interaction data from both primary tables. This operation is typically used for user account deletion, data privacy compliance, or system cleanup operations.
Deletion Scope:
Container States: Removes user's stored state from
container_statestableInteraction History: Removes all user interactions from
interaction_datatableComplete Cleanup: No residual user data remains after successful execution
Database Operations:
-- Remove user's container state
DELETE FROM container_states WHERE user_id = ?
-- Remove user's interaction history
DELETE FROM interaction_data WHERE user_id = ?Operation Characteristics:
Atomic Operations: Each DELETE is atomic, but overall operation is not transactional
Referential Integrity: Safely removes related data across multiple tables
Performance: Uses indexed user_id columns for efficient deletion
Audit Logging: Reports number of records deleted from each table
Privacy & Compliance Implications:
GDPR Compliance: Supports "right to be forgotten" requirements
Data Minimization: Enables removal of unnecessary user data
Security: Prevents unauthorized access to deleted user's historical data
Audit Trail: Logs deletion operations for compliance tracking
Error Handling:
SQLException: Database operation failures with detailed error logging
Partial Failures: If one table deletion fails, the other may still succeed
Exception Propagation: Database errors re-thrown to calling context
Transactional Considerations: Consider wrapping in transaction for atomicity
Performance Considerations:
Index Utilization: Leverages primary key and foreign key indexes
Batch Operations: Efficiently removes multiple records per user
Lock Duration: Minimal lock time due to indexed deletion
Space Reclamation: SQLite may require VACUUM for space recovery
Usage Patterns:
try {
storage.deleteUserData("user123")
println("User data successfully deleted")
} catch (e: SQLException) {
logger.error("Failed to delete user data", e)
// Handle deletion failure (e.g., retry, alert admin)
}Threading Context:
Executes on Dispatchers.IO for non-blocking database access
Safe to call from any coroutine context
Suitable for background cleanup operations
Parameters
Unique identifier for the user whose data should be completely removed from the database. Must match the user ID used in previous saveContainerState and saveInteractionData operations.
See also
Container state operations that create deletable data
Interaction operations that create deletable data
Coroutine context for database operations
Throws
If either deletion operation fails due to database connection issues, constraint violations, or other database-related errors.