ON DELETE CASCADE is a foreign-key action that automatically deletes dependent rows when the referenced row is deleted. In session storage, deleting a session removes every message belonging to it, preventing orphaned records and avoiding a manual delete sequence. section 4.4.1 section 4.4.2
Use the constraint to make parent-child deletion behavior part of the database schema:
- Let delete_session remove the session and rely on PostgreSQL to remove its messages automatically. section 4.4.2
Deleting a session
A session has many rows in messages through session_id. When delete_session deletes that session, PostgreSQL deletes the associated messages in the same database relationship, rather than rejecting the deletion or leaving orphaned rows. section 4.4.1 section 4.4.2


