I was wondering what the best way to store non-relational metadata is in a MySQL database would be? The data won't be queried, so no indexes need to be applied to the data.
Here is the first example I tried, it seemed good in theory, but it turns out that the ORM I'm using makes it difficult to parse into a useful structure:
CREATE TABLE test (
id INT(11) PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(255)
);
CREATE TABLE test_metadata (
id INT(11) PRIMARY KEY AUTO_INCREMENT,
test_id INT(11),
name VARCHAR(255),
value TEXT,
FOREIGN KEY (test_id)
REFERENCES test(id),
UNIQUE KEY `uk_test_id_name` (test_id, name)
);
Full example: http://sqlfiddle.com/#!2/9d84f1
Then the other solution I was thinking of trying would be just storing the metadata as JSON in another column in the schema, like so:
CREATE TABLE test2 (
id INT(11) PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(255),
metadata TEXT
);
There are probably a lot of downsides to doing it this way though, off the top off my head I can think updating the metadata would require an additional SELECT
before calling UPDATE
Which of these solutions would be best to store metadata in a relational DB? Or is there a better way I'm not seeing?