blitzjs.com
blitzjs.com copied to clipboard
Update docs with cascading deletes from Prisma
Good day.
I've been following the Blitz tutorial and so far it has been a great experience. However I noticed some outdated info in the docs that I believe is worth mentioning. The section about deleteQuestion
mutation states that:
Prisma does not yet support "cascading deletes".
However since version 2.26.0 Prisma does support cascading deletes via Referential actions. The caveat is that it is a Preview feature. But then again, so is React Suspense, which is used throughout the starter project.
It is worth noting that even without enabling the Referential actions feature, running blitz generate all/resource/etc.
creates the DB migrations that already have ON DELETE CASCADE
clause present on the foreign keys. When I looked up the initial DB migration, the Session table had ON DELETE SET NULL
for the userId
foreign key, while the Token table had ON DELETE CASCADE
for the same key. I am not sure if these ON DELETE
discrepancies are intended and what implications they had when the Referential actions feature is disabled. I still had to add onDelete: Cascade
clause in all foreign keys defined in schema.prisma
, even after enabling the feature.
We are getting close to 1.0, so let's leave it as is until it's stable. But we can go ahead and add a note mentioning the preview feature!
I understand. But what about the usage of alpha version of React and its experimental Suspense feature? Are they going to make it into the 1.0? I am just trying to understand the rationale for including some experimental features, but not others.
@arslancharyev31 sorry for the delay here! Since we are nearing 1.0, we are trying to minimize experimental things. React alpha is the only pre-stable thing we have now. React alpha is being used at facebook and the suspense feature we are using is extremely stable (within alpha). Does this make sense?
Blitz now defaults to Prisma 3 (blitz-js/blitz#2731) and Referential actions has been out of preview.
Mandatory relations (the Token
model) now defaults to ON DELETE RESTRICT
, so @relation(..., onDelete: Cascade)
is required for cascade deletes.
There are also several places not updated to say Prisma 3
https://github.com/blitz-js/blitzjs.com/blob/49fac464346fcb0ae9420161c65c4f1738bb3e1b/app/pages/docs/database-overview.mdx#L14-L16
https://github.com/blitz-js/blitzjs.com/blob/49fac464346fcb0ae9420161c65c4f1738bb3e1b/app/pages/index.js#L323
Referential actions has been out of preview
Maybe we can change the Tutorial — instead of adding a new DELETE, we can make the users update the Prisma schema.
There are also several places not updated to say Prisma 3
Fixed by a9dc52e