代码之家  ›  专栏  ›  技术社区  ›  oshirowanen

数据库结构帮助

  •  2
  • oshirowanen  · 技术社区  · 14 年前

    我正在尝试创建一个允许本地网络用户一起协作内容的系统。

    1. 创建内容,
    2. 应该记录谁编辑了什么和什么时候,
    3. 在页面中添加评论,

    我正试图提出一些数据库结构,但需要一些帮助。有人能帮我为这些要求创建一个好的结构吗?

    编辑:

    这就是我目前所拥有的:

    page table -
    page_id
    title
    content
    date
    inactive (0,1)
    author
    
    rights table -
    page_id
    user_id
    view (0,1)
    edit (0,1)
    delete (0,1)
    
    history table -
    page_id
    title
    content
    date
    inactive (0,1)
    author
    

    如何改进?

    2 回复  |  直到 14 年前
        1
  •  1
  •   Brett Rossier    14 年前

    我认为你所拥有的大部分都很好。我只是在展示设计的增加或改变,快速但粗略的估计:

    user
    ----
    user_id
    network_username ("Or Active Directory Name or whatever, you get the idea.
        Using user_id as a foreign key in other tables instead of the network
        name makes it easier if account names change.")
    
    role
    ----
    role_id
    name
    
    user_role
    ---------
    user_role_id
    role_id
    user_id
    
    page
    ----
    page_id
    author_user_id
    
    page_comment
    ------------
    page_comment_id
    parent_page_comment_id ("Self reference to allow for nested comments")
    page_id ("Even though you could conceivably look up page_id via
        parent_page_comment_id if you're dealing with a nested comment, that
        would involve N nested queries... so it's probably good to require this
        field be populated for every single record")
    user_id
    
    
    permission
    ----------
    permission_id
    page_id
    role_id ("To simplify, I'd stick solely to role-based access.")
    
    history
    -------
    history_id ("If you have high-volume edits, you may need to use date AND this
        to establish the order changes were made in.  Probably safest to use both
        right from the start.")
    page_id
    user_id ("caveat:  you won't know what role the user was in when a change was
        made.")
    old_title ("I'd prefix "old_" to all the fields just to make it intuitively
        clear.")
    
        2
  •  0
  •   Community CDub    8 年前