[SOLVED] Need help with RLS/SQL
I have 4 tables:
- userprofile
- blog (part of a user)
- posts (part of a blog)
- likes (part of a post)
There are 2 scenario's:
1. I am following a blog of the user: Now I want to see this blog appear on their profile
2. I am not following a blog: now I do not see any blogs, this should be private.
BUT, I should ALWAYS be able to see the total amount of likes, blogs and posts the user has.
What whould be the best approach to achieve this?
5 Replies
I won't talk much about the RLS side of this but I will touch on table normalization a bit, you don't want to be querying any of these tables at runtime to get a count of how many like, blogs or posts a user has. It's better to create a separate table to store all this information you will query regularly.
Thank you for your reply!
Do you mean like a materialized view? And what time period would you recommend to refresh in this case?
You could use those but I was referring to a completely separate table that would get updated using a trigger each time an update happens on any of the related tables.
Got it! Would such trigger be possible within Supabase, or is this something I'd have to do manually? Mind you I'm new to all of this really.
It's possible to do in Supabase as it's just a Postgres feature.