P
Prisma5mo ago
Abhishek

Triggering an Endpoint after the Cascade deletes the record of a model

i have a attachments model, where the images url are been stored that are been saved on the aws s3. If the attachment record gets deleted due to cascading. I want to trigger the endpoint to delete the image on that url also.
No description
1 Reply
jonfanz
jonfanz5mo ago
I don't think you want to do this. However: I don't know if this will work but you could try a query extension that performs an operation when attachments.delete is called. Honestly, I'm not sure how you would do something similar in any ORM. You might be able to accomplish this with some db hooks? But that's outside the scope of Prisma ORM The reason I don't think you should do this is that it opens you up to a lot more failure states. Let's say there's a db action that causes a large number of Attachments to be deleted. You then have to spend time deleting all of those objects from S3. All the while whatever client made this action is still waiting. They might not even care about the attached files in S3! It'd be much better to move this to an async process. Prisma Pulse is a product we offer that would help here, but you could also go a more "traditional" path which something like BullMQ if you're ok with running your own infra.
Prisma Client extensions: query component | Prisma Documentation
Extend the functionality of Prisma Client, query component
Prisma
Prisma Pulse | React to changes in your database
Pulse makes it easy for your apps to react to changes in your database, ensuring that the right events and actions are triggered.
Want results from more Discord servers?
Add your server