V
V
Vyacheslav Shevchenko2020-02-11 11:36:39
Software design
Vyacheslav Shevchenko, 2020-02-11 11:36:39

How justified is it to store information about files in a database?

Hello. The question is architectural. Let's say the project has a file repository. How generally justified to start a table to store information about the files (the file itself on the disk)? I think it's generally justified, but I'm not sure. As an example: a photo for a news item in the news list (preview_iamge). If we have a files table that lists all files (for now, we will assume that there are only pictures), then we store the file id in preview_iamge, and if there is no table, then the full path from the project root. When deleting a file, if we just put Null everywhere for preview_iamge for news, and then it is immediately clear that the file has been deleted. For images, we can store the resolution of images and even versions in different resolutions, it will be easier to search for them. How do other projects store information about files? Who thinks about this?

Answer the question

In order to leave comments, you need to log in

6 answer(s)
F
FanatPHP, 2020-02-11
@FanatPHP

So far, I have not seen a single reason to store information about files in the database in the description of the problem.
Any action should be caused by an urgent need, and not by abstract reasoning.
What a problem to find the right resolution version by postfixing the file name with the resolution - a puzzle
Other projects do what is required in their particular case.
If you do not need to store any additional information about the file, then you do not need to shove them into the database.
If a file is embedded in a database - for example, it can belong to several categories at once, then you simply cannot do without a database, and in principle there are no such questions.

M
Mikhail, 2020-02-11
@RuComMarket

there is another option:
when uploading a file, it is compiled into small medium full and saved original
in the database with one id you have 4 files that can be used for example for adaptability, or preview or detail output, and 3 types are minimized to reduce the amount of traffic

#
#, 2020-02-11
@mindtester

Bitrixoid to the brain and bones
and such a question? .. ahem..
store information about files in a database
these are features of the FS by that and the answer is simple - if you need features that the FS is not able to provide * - this is normal . otherwise - such a solution is redundant, and can be an unnecessary source of
upd * errors including response speed, for that matter

C
coderisimo, 2020-02-11
@coderisimo

Of course it's justified. Some even strive to shove the files themselves into the database :). And if from a practical point of view, then you can use aliases for files, save other related information, manage file access rights, and so on...

N
NubasLol, 2020-02-11
@NubasLol

How reasonable is it to store information about files in a database

Judging from the belfry of the development of the website c, it is justified. You will have an entity that will be able to work with these files, output them correctly, save them to various file systems (s3, locally, etc.). Pass them through a proxy to hang a watermark, know which one to hang. Access rights settings for the user. Quick count of the number of files, methods.
But I don't see any downsides to this approach.

V
Victor, 2020-02-12
@Levhav

In october cms there is a table with information about files. And in general it is convenient. I like.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question