views:

73

answers:

2

I am trying to create a system which allows local network users to collaborate content together.

Requirements: The user should be able to:

  1. create content,
  2. edit content (content created by anyone),
  3. records should be kept on who edited what and when,
  4. should easily be able to go back and forth between edits,
  5. add comments to pages,
  6. should be able to assign rights to created/edited pages (i.e. who can view them)

I am trying to come up with some database structures, but need some help. Could someone please help me create a good structure for such requirements?

EDIT:

This is what I have so far:

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

How could this be improved?

A: 

You could take a look at the tools used to build the SO site.

Lieven
I've already chosen the tools, I just wanted help with the database table(s) structure.
oshirowanen
Regarding the editing (with history), the link http://www.fogcreek.com/Kiln/ could prove helpfull (or do you already have a way version control the content?)
Lieven
I would like to create a version control system built into the system.
oshirowanen
+1  A: 

I think most of what you had is fine. I'm just showing additions or changes in the design, quick but rough estimate:

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.")
pheadbaq
Where could the title and content be stored for the page? Assuming it's in the page title? And would that mean I need to add an old_content to the history table too? Also, is it possible to remove the caveat mentioned by including the role_id in the history table and the page table?
oshirowanen
I think what you had was fine, with title and content in the page table. You wouldn't "have" to name the history content field "old_content," I was just saying it might make it more obvious what the field holds. Of course, the fact that the table is named "history" kind of indicates that. Like I said, I think most of the fields you defined originally are fine, I was just suggesting a few other tables, as well as how to set up the primary and foreign keys. As far as the caveat, do you really need to know what role someone was in when they made a change? I'd tried to keep things simple.
pheadbaq
Also, getting rid of the caveat would mean a more complex design. You'd end up needing a role history table that stored the dates/times when a user switched roles, and then cross reference that against the user_id and the date/time in the history table... ugh, it just makes things more complicated. But if it's truly necessary to know the role someone was in when a change was made, then it's certainly something to consider. A key question to ask all along the way during design is, "How will this data be used after the DB is built, how do I get the necessary info out of it?"
pheadbaq