开发者

Mysql design for a user with several items of data

I want to store notes, bookmarks, videos and images that belong to a user:

The simplified user table is as follows:

user: id, email, password_hash

A note contains a title and content, whereas a bookmark contains a title and a url

note: id, title, content, (user_id)
bookmark: id, title, uri
video: id, title, uri
images: id, title, uri

I could crea开发者_运维问答te a table for all these, however If I wanted to add something else, for example tasks, I would have to create another table for this. How do you suggest I design the tables?

Is mysql the best db for this, Or would something like mongodb be better?


As JamWaffles suggests you could have one table for content and one for content types, i.e.:

content: id, title, uri, content_type_id, user_id
content_type: id, name

EDIT: The content table could look like this:

-------------------------------------------------------------
| id |   title   |     uri      | content_type_id | user_id |
-------------------------------------------------------------
| 1  | 'My note' | '/note?id=1' |        4        |    56   |
-------------------------------------------------------------

And the content type table:

---------------
| id |  name  |
---------------
| 4  | 'note' |
---------------

I haven't actually used MongoDB but I guess you could use the following structure:

{
  "id": "...",
  "email": "...",
  "password_hash": "...",
  "notes": {
    "id": "...",
    "title": "...",
    "uri": "..."
  }
  "bookmarks": {
     ...
  }
}

MongoDB like other NoSQL databases have their advantages as well as disadvantages. You would have to evaluate your specific needs in order to determine which better suite yours. Personally I don't see why you couldn't use mysql for your proprosed database structure.

I hope this helps,
Per Flitig
Netlight Consulting

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜