One of the possible options for storing media files can be the following: we organize the media table where we store all the files (photos, videos, audio, etc.) with the most general information about the file.
Π’Π°Π±Π»ΠΈΡΠ° media id - ΠΏΠ΅ΡΠ²ΠΈΡΠ½ΡΠΉ ΠΊΠ»ΡΡ media_file_id - Π²Π½Π΅ΡΠ½ΠΈΠΉ ΠΊΠ»ΡΡ Π² ΡΠ°Π±Π»ΠΈΡΠ΅ media_class - ΠΈΠΌΡ ΠΊΠ»Π°ΡΡΠ° Π² ΠΏΡΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ (users, animals, audios, videos) filename - Π½Π°Π·Π²Π°Π½ΠΈΡ ΡΠ°ΠΉΠ»Π°, ΠΏΡΡΡ ΡΠΎΡΠΌΠΈΡΡΠ΅ΡΡΡ Π°Π²ΡΠΎΠΌΠ°ΡΠΈΡΠ΅ΡΠΊΠΈ ΠΈ Π½Π΅ Ρ
ΡΠ°Π½ΠΈΡΡΡ Π² ΡΠ°Π±Π»ΠΈΡΡ mime_type - MIME-ΡΠΈΠΏ ΡΠ°ΠΉΠ»Π° size - ΡΠ°Π·ΠΌΠ΅Ρ ΡΠ°ΠΉΠ»Π°
The table has a composite foreign key ( media_file_id , media_class ), which refers to another table that already sets the class for the file. For example, users can be stored in the users table
Π’Π°Π±Π»ΠΈΡΠ° users id - ΠΏΠ΅ΡΠ²ΠΈΡΠ½ΡΠΉ ΠΊΠ»ΡΡ first_name - ΠΈΠΌΡ last_name - ΡΠ°ΠΌΠΈΠ»ΠΈΡ email - ΡΠ»Π΅ΠΊΡΡΠΎΠ½Π½ΡΠΉ Π°Π΄ΡΠ΅Ρ nickname - Π½ΠΈΠΊΠ½Π΅ΠΉΠΌ
The link to the autark in the media table will contain the primary key user.id in the field media.media_file_id and the string 'users' in the field media.media_class . Styles like 50x50 can never be stored anywhere, but implied by default.
For a table of animals, you can create a separate table, each entry in which corresponds to one photo of an animal (file names are still stored in the media )
Π’Π°Π±Π»ΠΈΡΠ° amimals_photos id - ΠΏΠ΅ΡΠ²ΠΈΡΠ½ΡΠΉ ΠΊΠ»ΡΡ title - Π·Π°Π³ΠΎΠ»ΠΎΠ²ΠΎΠΊ author - Π°Π²ΡΠΎΡ ΡΠΎΡΠΎ animal_id - Π²Π½Π΅ΡΠ½ΠΈΠΉ ΠΊΠ»ΡΡ Π΄Π»Ρ ΡΠ°Π±Π»ΠΈΡΡ ΠΆΠΈΠ²ΠΎΡΠ½ΡΡ
animal
The media table will contain the primary key amimals_photos.id in the media.media_file_id field and the string 'amimals' in the media.media_class field.
If there are any video materials, you can create a separate table with parameters for video
Π’Π°Π±Π»ΠΈΡΠ° videos id - ΠΏΠ΅ΡΠ²ΠΈΡΠ½ΡΠΉ ΠΊΠ»ΡΡ description - ΠΎΠΏΠΈΡΠ°Π½ΠΈΠ΅ duration - Π΄Π»ΠΈΡΠ΅Π»ΡΠ½ΠΎΡΡΡ Π²ΠΈΠ΄Π΅ΠΎ
The media table will contain the primary key videos.id in the media.media_file_id field and the string 'videos' in the media.media_class field.
If there are any audio materials, you can create a separate table with parameters for audio files.
Π’Π°Π±Π»ΠΈΡΠ° audios id - ΠΏΠ΅ΡΠ²ΠΈΡΠ½ΡΠΉ ΠΊΠ»ΡΡ description - ΠΎΠΏΠΈΡΠ°Π½ΠΈΠ΅ duration - Π΄Π»ΠΈΡΠ΅Π»ΡΠ½ΠΎΡΡΡ Π°ΡΠ΄ΠΈΠΎ
The media table will contain the primary key audios.id in the media.media_file_id field and the string 'audios' in the media.media_class field.