I am currently designing a MySQL database that will store a variety of documents in different digital formats (mostly docs, spreadsheets, and pdfs). Each document will have several metadata values associated with it (a receipt might have metadata fields for date, store, and price, while a recipe might have metadata entries for various types of ingredients, serving size, and meal type). In order to be clear, the metadata I am storing is not about the table or database itself but is information about each type of document being stored and will have a different value associated with the metadata type for each document. I don't want to create a new table for each type of metadata being stored, but rather allow the users of the database to create additional metadata fields for each type of document as needed.
The problem I'm running into is the metadata's data type will be different depending on what the field is (for example, a business name field would be a varchar, while a dollar amount field would be a decimal type). I want to be able to search based on this data (all receipts with a date issued value before January 2nd for example), so I can't just store everything as a varchar. Currently I only see two ways to design this database:
- Create a separate table for storing each data type (ex. a text_metadata table, decimal_metadata table, and date_metadata table) and another table keeping track of the field name and what type it is.
- Have a single table for storing the values of all metadata, but have a different column for each data type and only use the column specific to that metadata field to store the actual data.
Both of these solutions seem really clunky. Does anyone have a more elegant approach to storing these types of metadata values?