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
- IMPORTANT! SOC-2 Request Failing
Issue requesting SOC-2. If tried other/private browser as well as filling in optional fields.
- Can you suppress row $meta data?
When using listRows with a 'select' query to limit the response [for performance], I'm still getting extra columns (eg. `$id`, `$sequence`, `$createdAt`, `$upda...
- CLI - get Database Totals
Is there a way with the Appwrite CLI to get table row totals (count)❓