-
Notifications
You must be signed in to change notification settings - Fork 690
Open
Description
AlaSQL currently parses CASCADE syntax but does not enforce the behavior. When a parent row is deleted or updated, child rows with ON DELETE CASCADE or ON UPDATE CASCADE are not automatically affected.
What needs to be implemented
ON DELETE actions:
- CASCADE: When a row in the parent table is deleted, automatically delete all rows in child tables that reference it
- SET NULL: Set foreign key columns to NULL in child tables when parent is deleted
- SET DEFAULT: Set foreign key columns to their default value when parent is deleted
- RESTRICT: Prevent deletion of parent row if child rows exist
- NO ACTION: Same as RESTRICT per SQL-99 standard
ON UPDATE actions:
- CASCADE: When parent key is updated, update matching foreign keys in child tables
- SET NULL: Set foreign key to NULL when parent key is updated
- SET DEFAULT: Set foreign key to default when parent key is updated
- RESTRICT: Prevent update of parent key if child rows exist
- NO ACTION: Same as RESTRICT per SQL-99 standard
Implementation areas
- Modify DELETE statement handler (
src/74delete.js) to check for child tables and apply CASCADE actions - Modify UPDATE statement handler (
src/74update.js) to check for child tables and apply CASCADE actions - Store foreign key metadata including ondelete/onupdate actions in table definition during CREATE TABLE
- Add validation for RESTRICT actions before allowing delete/update
- Handle circular dependencies and prevent infinite loops
Related
- Fixes parsing: CASCADE not supported (sqlite) #897
- Parser support added in: PR Add parser support for ON DELETE and ON UPDATE CASCADE in REFERENCES #2311
Copilot
Metadata
Metadata
Assignees
Labels
No labels