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
- Unknown attribute type: varchar / text
Since the `string` type is deprecated I tried using `varchar` and `text` in some newer tables, but when running `appwrite pull tables && appwrite types ./src/li...
- Query.search limitation
Since `string` is deprecated I used `varchar`, and now I cant use `Query.contains` , so I setup fulltext index and started using `Query.search` the issue is `Qu...
- Searching by attribute "name" requires a...
I have a table "products" with a few columns I'm trying to search by, but I get this error: ```json { "message": "Searching by attribute \"name\" requires a...