What structure to use in the database for the virtual file system?

I want to make a web application in witch, where there will be some users with different projects (for example, project c, C ++ project). My question is, how do I create three tables: users, projects, files? One user can have many projects (there will also be collaborative projects), projects can have folders (packages) and files, but in the file system I do not want this folder hierarchy to point to only pointers to a specific file from the database.

those. I am user1, and I have project1 with 3 folders in it: headers, resource, source, and there are several files in each folder or root file. The fact is that I want to get all the data associated with the project from user1 and put it in a tree view, but on the server all the files are in the same folder with randomly generated names.

+4
source share
1 answer

You can use a structure like the one below.

Alternatively, you can store your files in the database as a BLOB ( MEDIUMBLOB ).

 users id name ... projects id name ... user_projects user_id project_id folders id name project_id parent_folder_id ... files id filename parent_folder_id name_in_filesystem ... 

You have a users list and a projects list. The user_project table allows user_project to assign multiple users to a project and assign multiple projects to a user.

Each folder belongs to one project and can have parent_folder_id to allow hierarchies. Each file has a parent_folder_id , which is a link to the folder in which it is contained. name_in_filesystem is the random name that you use to store the file.

+5
source

Source: https://habr.com/ru/post/1303027/


All Articles