Back

Register changes on documents, "before update" trigger

  • 0
  • Databases
  • Functions
pitcairn1987
25 Sep, 2024, 20:34

Hi I want to have possibility to save history of changes on collection. When I save some changes, old value should save in another "history" collection. It should works like "before update" Trigger in SQL. What is best approach to do it in Appwrite?

TL;DR
Developers want to create a function that saves specific document changes in a history collection and trigger it when updating a document. The suggested solution involves creating a function to process requests, passing necessary data, logging current data in a different collection, and then updating it. They are looking for the best approach to achieve this in Appwrite.
Guille
25 Sep, 2024, 20:37

You need to do this to a specific collection or all your collections?

pitcairn1987
25 Sep, 2024, 20:43

for now only 1 collection

Guille
25 Sep, 2024, 20:48

I did something similar in a project: I created a function to process my requests (I call this function for each request). In the function I passed the databaseId, collectionId, and data to update. I did a similar endpoint to edit a document (it included documentId).

Then In the function I requested the current data, logged in a different collection, and then update it. I don't know if that meets your needs

Guille
25 Sep, 2024, 20:48

<@688415252471349251>

pitcairn1987
25 Sep, 2024, 21:05

Ok. So am I good understand. I have to create function only to save specific document in history collection, and next I have to trigger this function when I'm updating document in my "real" collection?

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more