开发者

Groups-People Database Design - Need advise

I'm developing an application in which users upload pictures to server and then send email to people they choose with a link that shows these pictures.

My question is about organizing the people in a database (I'm using MySQL).

I would like each user to have people tree like this:

  • Family
    • Mom
    • Daddy
    • Jonathan
  • Close Friends
    • David
    • Ronny
  • Others
    • Julia
    • Piter
    • Alex
  • Tanya (does not belong to any group)

I thought about the following organization in the database:

Emails Table (all users people emails)

Groups-People Database Design - Need advise

Groups Table (all users groups)

Groups-People Database Design - Need advise

People Table (all users people)

Groups-People Database Design - Need advise

In the Emails Table, there will be no two identical emails. name in Emails Table is the name that the user gave to the person when he added his email (I call it default name). Each user may have different name for the same person. Hence, this is what name in People Table for. name=NULL in People Table means that the default name will appear in the people tree. group_id=NULL means that this person does not belong to any group.

Does all this seems reasonable ?

In addition, as you can see, there is some kind of emails sharing between the users. This means that if Julia changed David's email, all other us开发者_运维技巧ers will also see this change (they will receive an email regarding this change). Do you think this can lead to problems ?

I'll appreciate your opinion !


Oy. A given email can be associated with different "people"? I would argue the semantics of that are a quite ugly. I would rename the people table Contacts. I would also rename the 'name' field in the Emails table to DefaultName to indicate it's strictly a fallback.

Semantics aside (which are a big deal, if someone else has to use this db), you reference an owner as a foreign key using varchar(20). There's no indication of what it is referencing, I assume it is some sort of Owners table, with a username as the primary key. I would recommend an int surrogate key... What happens if a user wants to change their username?

Lastly, the stickler in me would change the 'groupless' contacts. I would make a default group for each contact, call it _Groupless, and assign 'groupless' contacts like Tanya to the _Groupless group. The application can sort out the details. I don't particularly like optional foreign keys.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜