0

I'm building an application that contains a database of movies. Movies have various fields such as a title, directors, actors, etc. I also want to include a movie cover with each row in the movies database. I currently have a column in my database called "cover_path" which contains the absolute file path to an image (the movie cover). I will similarly have one called "movie_path" which contains the path to the actual movie.

Are there better ways of storing files in a database and by storing the file path to an image in the database am I defeating the purpose of data independence?

Chris Bell
  • 51
  • 1
  • 6
  • The problem with file paths in the database comes when you need to move the database to a different machine, or the disk drive fails, or you need to expand your disk system and change its name. That said, storing the file name may still be better — and maybe you store the name relative to a configurable root directory, to accommodate the various changes (or a set of root directories, perhaps). – Jonathan Leffler Jul 20 '17 at 06:32
  • I agree, the application is for personal use so I can store the base file path in a configuration file in the application and then for anybody who wants to run the application themselves they can just edit that config file – Chris Bell Jul 20 '17 at 17:32

1 Answers1

0

Using file paths have more advantages then storing binary data in the database. This is a good discussion on this subject.

Though I'm not sure in which way would this defeat the purpose of data Independence on any level.

doriclazar
  • 97
  • 7
  • I think it might defeat the purpose of it because whether you store the file path in the application itself or in the database that path is still subject to change which would break the application using the file. Because of this I don't think it matters whether or not the file paths are directly hard coded into the application or the database because if they change it would still break. – Chris Bell Jul 20 '17 at 17:30
  • If I understood you correctly: You have a movie_path connected to movie_title, and movie_id. The application requests the movie_path where movie_id, or movie_name equals to users request. If the path of a file change, value of movie_path changes, and the application is still gonna get the correct result (where to look for a movie in the file system). Therefore, you shouldn't hardcode the paths, you should make a system (in admin panel) that changes the value of movie_path, and cover_path fields when such changes occur. – doriclazar Jul 20 '17 at 17:59