Hello!
I'm working on migrating a project from Airtable to Appwrite, but I am a little confused about how to handle my schema.
Background: My site is a public listicle, and un-authenticated users fill up various forms to enquire about various properties on the site.
Currently:
- I have one table, which we can call 'Form Submissions' (containing user email, and info about the properties they enquiring about)
- I have a second table, which we can call 'User Callback Requests' (again, containing user mail, and info specific to their call back requests)
Problem:
- I am required to create a new table this time, called "User Activity". The purpose of this table is to be a unique list of user emails, user activity info (incremental count of form Submissions table, as incremental count from Callback Requests table).
- The above logic should be triggered automatically update at every document inserted into the two other tables mentioned above.
- I know with Postgresql i could've made triggers to handle this, but how do I do this in App Write?
You can create an Appwrite function to trigger on document creation.
In depth guide on functions: https://appwrite.io/docs/functions
Ah! Thanks Stephen!
So I'd basically need to maintain a separate codebase in a sense, to handle this. Got it.
Within the function, Is there a way I can ascertain which document was JUST updated (that triggered this function)? Or do I just need to pull all documents that were created in the last X minutes and ascertain which one triggered the function?
The APPWRITE_FUNCTION_EVENT_DATA
variable will have the newly updated document (for an update document event)
Thank you so much! Would this also trigger when a document is created?
I can't find a documentation page on this, if you could point me to that it'll be super helpful.
Thanks @Steven!
Yes document creation is an event too. The link to all the events is in the first paragraph
You're the best, Steven! Thank you
Recommended threads
- Seed db
hello there... is this correct way to seed appwrite
- Query Appwrite
Hello, I have a question regarding Queries in Appwrite. If I have a string "YYYY-MM", how can I query the $createdAt column to match this filter?
- Type Mismatch in AppwriteException
There is a discrepancy in the TypeScript type definitions for AppwriteException. The response property is defined as a string in the type definitions, but in pr...