I’m working on a project at the moment that has a rather unusual
requirement and I’m hoping to get some advice on the best way to handle
or even some pointers to info that can help me build a solution.
Ok, so this is what I need to do. The application stores and manages
various types of media files but each deployment of the application has
completely different metadata requirements for the media files.
This metadata can contain an arbitrary number of fields of different
(single line text, multi-line text, checkboxes, selected values, etc.)
also often requires validation particularly presence and uniqueness
The application needs to be able to easily retrieve values and most
importantly has to be able to handle full searching capabilities on
One option I considered was using a property list arrangement where the
database table simply contained a property name and value for each
field of each media file. However, when prototyping this solution it
quickly became apparent that it simply wasn’t going to be efficient
for the searching and retrieval of records particularly when the
can be reasonably large e.g. a recent deployment had 3000 media files
there were over 20 metadata fields. Also, the queries to do a search and
retrieve the relevant records quickly became very complex.
Another option that the system is currently using is that the metadata
config is defined upfront and a migration is run during deployment to
create a the table and model with a standard name so that the media
can be associated with it which the system then uses. This generally
pretty fine but it does cause some significant deployment and testing
For example, writing unit tests becomes much more challenging when you
don’t know the config until deployment. Although I could write a sample
config and test the code that way, it won’t allow me to test the
requirements of a particular deployment.
Similarly, in development, it currently requires me to copy a migration
from the config into the main folder, run it, do all of my testing and
development and then I have to remember to rollback and remove that
migration from the main folder so that the application is in a standard
state. This particularly becomes challenging when I’m bug fixing and I
to have the application in a specific configuration for testing and
debugging purposes. Trying to switch between the various configurations
becomes a real nightmare.
Ideally, what I would like is to be able to dynamically create the table
and model including validations, etc. from a config file when the server
started. Even better would be if I could maintain multiple metadata
in the one database with each one having its own table so that all I
to do to switch between them is change which config file the application
I’m sure this can be done with Rails but there is very little
that I’ve been able to find that can point me in the right direction of
to build it during my research over the past few days so any help or
suggestions would be much appreciated!