I am building a website as a personal project just for some experience in a new web framework and want to make sure I model my SQL database in a good way with the appropriate relationships before building it out and getting myself in too deep. I'm coming over from using MongoDB so this will be my first application in which I have to model the SQL database.
This application will allow users to join and create groups for discussion, add categories to the groups and then post topics to a specific category in a group.
My application will have four main things: Users, Groups, Categories and Topics (assuming no replies to topics, just a simple posting for users to read).
My current advance
This is what I have so far (FK = Foreign Key):
User
- id
- username
- password
Group
- id
- title
- description
- owner (FK user-id)
Category
- id
- title
- group (FK group-id)
Topic
- id
- title
- author (FK user-id)
- category (FK category-id)
Membership
- id
- group (FK group-id)
- user (FK user-id)
Responses to comments
The rules are:
- A user can own/create multiple groups and can join multiple groups
- A user can create multiple categories within the group that they own/created
- Members of a group can create multiple topics within a category
- There can't be duplicate categories within the same group
I am in no capacity a database expert and took one course on database a year ago so any feedback is appreciated
Best Answer
I think it looks about right for the defined business rules that you name... There's probably more to it but your structure seems pretty much whats needed in this case.
I would probably separate the Categories altogether, and then add a new table to store categories per group that way you dont end up with a bunch of duplicated categories on that table.
Something like: