I am new to web development and am trying to implement a website where users can upload photos and other files (i.e. .doc, .xls, .ppt, .txt, .pdf,etc…) on profile pages, posts and comments. I am using an s3 bucket for the file storage and will use a mysql database to store the file urls and other associative data. What I am confused about is the following:
Which of these is the best idea?
a) create a files tables for each of the following: profiles,posts,comments and then get all the files associated with the id(A FK) of the specified object(the post, the comment, or the profile).
b) create one files table that has a field named “type” which can be either “profile”,”post”,”comment”
and a field named “id” which is a FK of the the id of the table specified in the “type” field.
c) use a completely different schema that anyone finds more advantageous
EDIT: I want each file to be associated to the uploader(user_id) but also attached to the entity it was uploaded on(i.e. profile,post,comment)
I would create one table
FileslikeIf a
Post,CommentandProfilecan contain only one file you can add thefile_iddirectly in the tables likeIf they can have more then one file you’ll need a mapping table like: