-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add cascading deletion info #145
Conversation
Codecov Report
@@ Coverage Diff @@
## master #145 +/- ##
=======================================
Coverage 95.90% 95.91%
=======================================
Files 73 74 +1
Lines 1857 1860 +3
Branches 205 203 -2
=======================================
+ Hits 1781 1784 +3
Misses 75 75
Partials 1 1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks OK.
One possible gotcha that comes to mind is that we often express ON DELETE CASCADE
in Postgres and use CASCADE_DELETE_INVALIDATE_CACHE
in Entities, the logic being: let Postgres's schema be the source of truth of how to handle foreign-key deletions, and invalidate the entity cache to let the next read operation fill it with the correct value.
CASCADE_DELETE_INVALIDATE_CACHE
doesn't actually issue any DELETE
queries. It might not delete any entities at all (except for the first one being deleted that started the cascade).
So, if triggers want to behave differently based on whether a row is actually being deleted, the entity's inbound FK edges needs to be annotated with CASCADE_DELETE
or the programmer needs to be sure that Postgres has an ON DELETE CASCADE
constraint.
(The motivation for this PR sounds like it is to distinguish between cascading and non-cascading operations, which shouldn't be affected by the behavior described above, which is just something else to watch out for.)
Yeah, I think for now we assume that As for this PR, we should continue with this assumption and assume that all cascades detected by entity will actually match those done in the database. |
Co-authored-by: James Ide <ide@users.noreply.github.com>
Why
The use case for this is as follows:
How
This feature lets us solve this by inspecting the value of the cascade to see what case it's being deleted in. If it is being deleted in the normal case (no cascading info or different type of cascade) then we block the deletion in a beforeDelete trigger. If it is being deleted in a cascade deletion case we allow the deletion.
Test Plan
Run tests.