I'm currently working with a Supabase database that comprises several tables, including 'users' (for user metadata), 'network' (for user relationships like followers, following, and premium followers), 'image_posts,' 'video_posts,' and 'audio_posts' for different types of user-generated content.
The 'network' table has the following structure:
Table network {
id int PK
user_id uuid FK
follower_id uuid FK
connection_type Text // e.g., follower, premium_follower, blocked
is_accepted bool
sent_on TIMESTAMP
}
The all 'post' tables has the following structure:
Table image_posts {
id int PK
user_id uuid FK
post_type image
content image_url
caption TEXT
reach TEXT // is this post for followers or premium_followers
created_on TIMESTAMP
}
My goal is to fetch posts from the 'image_posts,' 'video_posts,' and 'audio_posts' tables based on whether a specific user ('USER A') is following another user. Additionally, I need to consider the 'reach' condition in the post table and the 'connection_type' in the 'network' table.
For example, if a user is a premium follower and not blocked, they should be able to retrieve all the premium posts from all the post tables of the users they are following. This scenario is akin to a social media platform.
I attempted to retrieve the posts using the supabase.from('image_posts', 'audio_posts', 'video_posts').select method, but I'm uncertain if this is the most efficient approach.
Here are my questions:
- Should I contemplate merging all the post-related tables into a single 'posts' table to simplify queries and data management?
- Alternatively, is it better to maintain separate tables for each post type, considering my specific use case and migration from Firebase?
Currently Using this:
Future<void> fetchAllPost() async {
try {
await supabase
.from('network')
.select('user_id')
.eq(
'follower_id',
currentUuid,
)
.eq(
'is_accepted',
true,
)
.then(
(value) async {
for (var user in value) {
final postData = await supabase
.from('users')
.select(
'first_name,last_name, image_posts(*), audio_posts(*)',
)
.eq(
'user_id',
user['user_id'],
);
print(postData);
}
},
);
//
update();
} catch (e) {
if (kDebugMode) {
print(e);
}
}
}
I greatly appreciate your guidance, especially as I transition from Firebase to Supabase. Thank You!