Cascading Deletes - Implementation Strategy for SQL connector #48
Labels
team/schema
Issue for team Schema.
tech/engines/introspection engine
Issue in the Introspection Engine
tech/engines/migration engine
Issue in the Migration Engine
tech/engines/query engine
Issue in the Query Engine
Milestone
Goal: This issue describes how we plan to implement the feature of cascading deletes available in the Prisma Schema Language.
Idea: We would like to leverage SQLs
ON DELETE CASCADE
feature wherever possible. However it does not support all the usecases of Prismas cascading deletes. The idea is that the SQL feature is used as often as possible and shims are implemented where necessary in the query engine. The parts that need to be shimmed are indicate with a 🚨 below.Problems:
@relation(onDelete: CASCADE)
on a field implies a SQL levelON DELETE CASCADE
on the column of the related field. 💥onDelete
annotation. On the SQL level there is only one column, and therefore only the behavior for one side can be expressed on the SQL level.Analysis of where the SQL On Delete Cascasde works and where not
One To Many: Cascade from the Parent.
This could work purely on the SQL level and could also be introspected from the DDL.
Prisma schema:
corresponding SQL:
Semantics:
One To Many: Cascade from the Child.
This cannot be expressed on the SQL level and would need to be handled by Prisma. We could also not introspect this case.
Prisma schema:
corresponding SQL:
Semantics:
One To Many: Cascade from both Sides
This cannot be fully expressed on the SQL level. We would need a mix of Prisma level and SQL level handling. We could therefore also not introspect this case.
Prisma schema:
corresponding SQL:
Semantics:
Many to Many
Here the SQL level
ON DELETE CASCADE
statements merely ensure that there are no dangling relation entries after one of the connecting nodes are deleted. They have no connection to the Prisma level semantics. The Prisma level ones cannot be expressed in the db and therefore can also not be introspected. Here for all cases (CASCADE on child, CASCADE on parent, CASCADE on both) the implementation needs to happen on the Prisma level.Prisma schema:
corresponding SQL:
Semantics:
The text was updated successfully, but these errors were encountered: