SQL Server: Detect referential action cycles #2113
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implementing an early detection of cascading cycles, allowing us to highlight the relations and to give a better error than what SQL Server is giving us.
Examples what we get here.
Self-relation
A self-relation is a cycle, and a special case of the feature. We give a different message in these cases, where the user can solve the problem by adding
onDelete: NoAction, onUpdate: NoAction
to one of the sides.Cycle between two tables
If we refer a table that has a relation back to the original table, one of the relations needs to have
onDelete: NoAction, onUpdate: NoAction
set to solve the issue.Hop over one table
A cycle where we go over one table, and then back to table
A
.Multiple separate paths between two tables
The referential actions can be in any side of the relation to matter. Here we have a link between
A
andB
,C
andB
,C
andA
.Implicit values in errors
If referential actions are not written to the relations, but they have an effect to the cycle errors, we write them to the error message.
Closes: prisma/prisma#4580
Closes: prisma/prisma#5782